how to integrate a discrete function ?

9 views (last 30 days)
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 ?

Accepted Answer

Roger Stafford
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
jaden
jaden on 8 Jan 2014
dear roger it seems to me that you were so iritated with my choice of words in my question that you fail to notice that all those words were in english and thus easy to understand. the function i wanted to integrate as it is clearly mentioned in my question was x*c*x'. since c is a constant matrix and y is just a set of values corresponding to each element of x through the time (t) , the only remaining variable that could be used as the independent variable is t .obviously by my "interpolate" remark ,i just wanted to tell readers that it is not possible to fit a continious function such as sin(t) to these set of discrete data for each column of y and it should be solved as discrete function . and by my whole "plot the result of integral in correspondence to t" remark ,it is clear that a cumulative integral is needed otherwise we would obtain only one number which is not suitable for ploting. so what you assumed was THE ONLY LOGICAL WAY of interpretation of my question and any way your solution is correct so thanks for your help.
Toby Snaire
Toby Snaire on 8 Oct 2020
Jaden that was a rollercoaster

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!