From: Windell on 14 Feb 2010 05:56 Hi, I have a set of data points in which I would like to numerically integrate using trap. Rather than just calculate the area under the curve, I would like to plot the integral with respect to time. So what I am trying to do is perform the integral between two times, increment the time step to integrate and populate a vector with the result so I can plot the integral with time. Here is the section of code in my program where I am trying to do this. This is only a section of my entire code so it may look a bit incomplete. %calculate rotational speed of motors. for i=1:length(z) for n=1:i time_interval(i,1)=t(i,1); func(i,1)=ang_accel(i,1); end react_1(i,1)=trapz(time_interval,func) end figure plot(time_interval,react_1) Right now my code produces an error: ??? Error using ==> permute ORDER contains an invalid permutation index. Error in ==> trapz at 44 y = permute(y,perm); Error in ==> solver at 86 react_1(i,1)=trapz(time_interval,func) Any suggestions? Thanks! Windell
From: John D'Errico on 14 Feb 2010 07:04 "Windell " <windelljones(a)gmail.com> wrote in message <hl8ksi$8vp$1(a)fred.mathworks.com>... > Hi, I have a set of data points in which I would like to numerically integrate using trap. Rather than just calculate the area under the curve, I would like to plot the integral with respect to time. So what I am trying to do is perform the integral between two times, increment the time step to integrate and populate a vector with the result so I can plot the integral with time. > > Here is the section of code in my program where I am trying to do this. This is only a section of my entire code so it may look a bit incomplete. > (snip) > Any suggestions? Thanks! Only a question. Why reinvent the wheel? Why not simply use cumtrapz? If you did not know that cumtrapz exists, read the help. The help (or doc) for trapz will have pointed out the existence of cumtrapz. John
|
Pages: 1 Prev: imnoise and de-noise problem Next: changing select values in a vector |