From help-octave-request at bevo dot che dot wisc dot edu Tue Jan 19 01:37:46 1999 Subject: RE: diff(x) question From: Van den Eynde Gert To: help-octave at bevo dot che dot wisc dot edu Date: Tue, 19 Jan 1999 08:37:32 +0100 > > t=[1:.1:10] > x=sin(t) > and I want to plot the derivative of sin(t) (but I want to compute it) > > I tried > y=diff(x) > > and then plot(t,x,t,y) yields me an error message that states the > the vector sizes must be the same.. so I did > plot(t,x,[1.1:.1:10],y) > > and it worked, but the y is really small and never goes beyond .1 in > value. Do you think you could point me in the right direction? > I guess I'm differentiating wrong, how should this really be done? > Diff computes forward differences. Not the derivative. If you want to approximate the derivative by using forward differences you have to divide by the step h with which you make your function discrete. In this case h = .1 df f(t+h) - f(t) -- (t) =~ --------------- + O(h) dt h Sincere greetings, Gert Van den Eynde ''''' (-o-o-) _________________________.oooO--(_)--Oooo._________________________ | Gert Van den Eynde mailto:gvdeynde at sckcen dot be| | | SCK-CEN http://www.sckcen.be/people/gvdeynde | | FLINS | | Boeretang 200 | | B-2400 Mol .oooO | | Belgium ( ) Oooo. | |___________________________\ (____( )____________________________| \_) ) / (_/