Results 1 to 10 of 10

Math Help - Help:Tiny code snippet for area under the curve

  1. #1
    Newbie
    Joined
    Jun 2008
    Posts
    5

    Unhappy Help:Tiny code snippet for area under the curve

    Hello everyone,
    I'm new to this forum and I have an issue that I could use some help me. I have written a tiny function to calculate area between two curves.
    I have 3-d, cartesian (x,y,z) data from a person performing a movement which is being recorded by IR-cameras.
    Now, the function takes in 3 arrays from two separate files(actual data and projected data) namely their x,y and z co-ordinates and then calculates area between two curves separately for the XY plane (think side view) and XZ plane (think top view).
    The first curve is data collected from the person. The second curve is data projected by a model.

    I need to know how to normalize the output from the function. Since the data starts and stops at different co-ordinates the output area is meaningless until it can be normalized.

    Attached is the code. it is quite simple. Im using "cumtrapz".
    Attached Files Attached Files
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lonedesi View Post
    Hello everyone,
    I'm new to this forum and I have an issue that I could use some help me. I have written a tiny function to calculate area between two curves.
    I have 3-d, cartesian (x,y,z) data from a person performing a movement which is being recorded by IR-cameras.
    Now, the function takes in 3 arrays from two separate files(actual data and projected data) namely their x,y and z co-ordinates and then calculates area between two curves separately for the XY plane (think side view) and XZ plane (think top view).
    The first curve is data collected from the person. The second curve is data projected by a model.

    I need to know how to normalize the output from the function. Since the data starts and stops at different co-ordinates the output area is meaningless until it can be normalized.

    Attached is the code. it is quite simple. Im using "cumtrapz".
    You need to be clear about what you are trying to calculate. What you are doing in your code snippet does not calculate the area between curves, at best it calculates the difference in the areas under the curves.

    If you are really interested in the area between the curves; that is:

    A=\int_{x=x_0}^{x_1} |y_1(x) - y_2(x)| \; dx

    then one approach is to interpolate the curves onto uniform set of x's, then numericaly integrate the absolute value of difference in the y's at corresponding x's.

    If the curves are realy functions of time it might be better to interpolate them onto a set of uniformly spaced time points then you would be interested in something like:

    A=\int_{t=t_0}^{t_1} |(y_1(t) - y_2(t))| \left|\frac{dx}{dt}\right| dt

    RonL
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jun 2008
    Posts
    5

    Hey Captain Black

    Hi Captain Black,
    Thank you so much for replying. What you say makes sense. However as I said first I am extremely poor with MATLAB programming. Is there some way you could perhaps help me with the code? Or is that too much to ask?
    Even a rough sample would suffice. Each input file contains 3 columns of data namely the x,y and z co-ordinates. If need be then I could send you a sample file.
    Is it possible?
    Once again...thanks so much for replying.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lonedesi View Post
    Hi Captain Black,
    Thank you so much for replying. What you say makes sense. However as I said first I am extremely poor with MATLAB programming. Is there some way you could perhaps help me with the code? Or is that too much to ask?
    Even a rough sample would suffice. Each input file contains 3 columns of data namely the x,y and z co-ordinates. If need be then I could send you a sample file.
    Is it possible?
    Once again...thanks so much for replying.
    If you are not in a hurry yes.

    RonL
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by CaptainBlack View Post
    If you are not in a hurry yes.

    RonL
    Also think about what you really want, if you are trying to measure how well one trajectory models the other you might well be interested in the integral of the absolute value of the 3-D seperation over time, rather than the seperation of the projections on to the x-y and x-z planes.

    RonL
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Newbie
    Joined
    Jun 2008
    Posts
    5
    Im not in a rush. This could wait a day or two. Is that ok?
    Thank you thank you thank you !!!
    Im going to send a sample file now. Two actually. In the first file called scrap the 2nd,3rd and 4th columns are x,y and z data. In the second file called model the first second and third rows are x,y and z data.
    Attached Files Attached Files
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Newbie
    Joined
    Jun 2008
    Posts
    5
    The goal here is to see how well the model predicts data so yeah im trying to compare the two data sets. since previous comparisons were done separately in the xy and xz planes i was thinking of moving forward with that. but if you could help me with the code for 2-d then i can definitely try and modify it for 3-d. thanks captain black. believe it or not ive been stuck on this for almost a month now.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lonedesi View Post
    The goal here is to see how well the model predicts data so yeah im trying to compare the two data sets. since previous comparisons were done separately in the xy and xz planes i was thinking of moving forward with that. but if you could help me with the code for 2-d then i can definitely try and modify it for 3-d. thanks captain black. believe it or not ive been stuck on this for almost a month now.
    Is the first colum in scrap.xls a time, and are the points in the second spreadsheed for the same times?

    RonL
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Newbie
    Joined
    Jun 2008
    Posts
    5
    Yes, the first column in scrap.xls is the time column. The second spreadsheet i.e. model.xls does nt have a time stamp because the inputs to the model are only the starting and ending x,y and z co-ordinates and the model predicts values between the starting and ending points. Unless im mistaken you dont really need to compare the time between actual and model. Ive only been using columns 2,3 and 4 in actual data and columns 1,2 and 3 in model data for my calculations.
    Follow Math Help Forum on Facebook and Google+

  10. #10
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lonedesi View Post
    Yes, the first column in scrap.xls is the time column. The second spreadsheet i.e. model.xls does nt have a time stamp because the inputs to the model are only the starting and ending x,y and z co-ordinates and the model predicts values between the starting and ending points. Unless im mistaken you dont really need to compare the time between actual and model. Ive only been using columns 2,3 and 4 in actual data and columns 1,2 and 3 in model data for my calculations.
    No, can't do this with a reasonable amount of effort because the data are not of a form that makes this easy to do (the fact that the x's in scrap are not monotonic is the first problem).

    It would be doable if there were a time index in the model data file or the x's in both files were monotonic, but otherwise this not a problem that can be dealt with in a reasonable amount of time.

    RonL
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Area under curve
    Posted in the Algebra Forum
    Replies: 1
    Last Post: April 24th 2010, 04:58 AM
  2. Three tiny questions
    Posted in the Calculus Forum
    Replies: 1
    Last Post: October 9th 2009, 03:45 AM
  3. Area Between the Curve...
    Posted in the Calculus Forum
    Replies: 3
    Last Post: May 23rd 2009, 02:09 PM
  4. Area Under Curve
    Posted in the Calculus Forum
    Replies: 4
    Last Post: June 11th 2008, 10:01 AM
  5. tiny spheres conducting
    Posted in the Advanced Applied Math Forum
    Replies: 9
    Last Post: February 26th 2008, 07:21 PM

Search Tags


/mathhelpforum @mathhelpforum