if i have a vector x=[0 6 7 7.....] and this x is measure with respect to a time vector then how can we find the derivative like dx/dt like the simulink block has the drivative, which computes with respect to simulation time but what can be done i case of MATLAB how this time vector can be differentiated with the x vector becasue both contain values. Any idea will be appreciated.

1 Kommentar

Rusty
Rusty am 17 Jan. 2015
Hi, I have made a program for you. Do you want the answer?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Kevin Claytor
Kevin Claytor am 8 Aug. 2012

4 Stimmen

A simple brute force numerical derivative would be find the change in x and divide by the change in t;
dx = x(2:end) - x(1:end-1);
dt = t(2:end) - t(1:end-1);
v = dx./dt

5 Kommentare

Jerry
Jerry am 8 Aug. 2012
thats cool, thanks
Greg Heath
Greg Heath am 8 Aug. 2012
Bearbeitet: Greg Heath am 8 Aug. 2012
That is a difference approximation that can be interpreted to be valid between data points. In modelling some physical phenomena it is necessary to use a central difference approximation. For interior points
dx(i) = (x(i+1)-x(i-1))/2
dx(1) and dx(end) depend on the boundary or initial conditions determined by the problem you are trying to solve
Hope this helps.
Greg
Instead of using
dx = x(2:end) - x(1:end-1);
use the equivalent MATLAB fuction:
dx = diff(x);
Same for dt.
Jerry
Jerry am 12 Aug. 2012
diff gives the same output but my problem is my length is decreasing, I must agree with Greg here but how can we have a way that after applying diff or gradient the size remains same to the original vector since due to diff it become n-1 ,by mean of interpolation or what how shud v keep it to the original size? I have posted another question for this I hope you can help me on this since i developed the whole code myself by taking constant help from you guys.
Jerry
Jerry am 12 Aug. 2012
Greg Thanks i think i got your point here... for initial and boundary conditions, ok can if i have an array
X=[ 0.1000 0.0844 0.0434 -0.0090 -0.0559 -0.0831 -0.0832 -0.0574 -0.0152 0.029] Which shows the position and time array with respect to that position is T= [0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000 4.5000]
can i like take time 0 as initial value and the last value as boundary condition.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 8 Aug. 2012

Kommentiert:

am 17 Jan. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by