how to integrate a discrete function ?

7 次查看(过去 30 天)
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 ?

采纳的回答

Roger Stafford
Roger Stafford 2014-1-5
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 个评论
jaden
jaden 2014-1-8
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by