how to integrate a discrete function ?
9 views (last 30 days)
Show older comments
i want to integrate a function in form of x*c*x' . c is a 5*5 constant matrix . x is a 1*5 vector which is actually a row of a 4000*5 matrix y that would indicate value of every element of x at each time step ( 4000 time steps as t=0:0.01:39.99 ). at the end in a plot it must be shown value of this integral in correspondence to t . there is no way to interpolate an analytical function to any column of y . cumtrapz gives a cumulative result and trapz gives nonthing since at every time step x*c*x' produces just a scalar value. is there any way to make this right ?
0 Comments
Accepted Answer
Roger Stafford
on 5 Jan 2014
To "make this right" you need to decide just what your function is, Jaden. What are its independent and dependent variables? Is time, t, the independent variable with respect to which you are integrating? Is the value of x*c*x' for each row of y the dependent variable? Also do you wish to find a single integral or the cumulative integral with respect to t as t increases from 0 to 39.99? What exactly did you have in mind by the remark "there is no way to interpolate an analytical function to any column of y"? These are concepts you need to straighten out in your own mind before you can hope to solve this problem. Your description seems to me to be rather confused as to these matters.
If we assume that t is the independent variable and x*c*x' for each row of y the dependent variable and that you wish to find the cumulative integral with respect to t, then you would do:
z = sum((y*c).*y,2);
I = cumtrapz(t,z);
It should give you a 4001 by 1 vector as a result.
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!