is possible use some function to find derivatives of a vector?
Show older comments
by example:
NO2=( 1.1 2.4 3.3 4.7 5.9 6.0)' that corresponding to depth: Z=(4.5 6.2 8.4 10.3 12.5 14.8)'
I want find d(NO2)/dz and d^2(NO2)/dz^2
Exist some function that calculate this?
Answers (3)
Azzi Abdelmalek
on 30 Nov 2012
Edited: Azzi Abdelmalek
on 2 Dec 2012
Edit
NO2=[1.1 2.4 3.3 4.7 5.9 6.0]
Z=[4.5 6.2 8.4 10.3 12.5 14.8]
d1=diff(NO2)./diff(Z)
d2=diff(NO2,2)./diff(Z(2:end)).^2
6 Comments
Azzi Abdelmalek
on 1 Dec 2012
Look at edit
Jan
on 1 Dec 2012
Usually "d2/dz2" means the 2nd derivative, not a squaring.
Azzi Abdelmalek
on 1 Dec 2012
Edited: Azzi Abdelmalek
on 5 Dec 2012
dy and dt are not the same, dt don't change while dy is changing.
Try this for x-abssisse
t=1:10
diff(t,2)=
0 0 0 0 0 0 0 0
Azzi Abdelmalek
on 2 Dec 2012
Edited: Azzi Abdelmalek
on 2 Dec 2012
- diff(y)./diff(t) is an approximation of the first derivative g=dy/dt, In general diff(t) is a constant, then diff(y)./diff(t)=cst*diff(y) , with cst=unique(1/diff(t))
- the second derivative f=d(dy/dt)/dt is approximated by diff(cst*diff(y))./diff(t)=cst*diff(cst*diff(y))=cst^2*diff(diff(y))
- finally f=diff(diff(y))./diff(t).^2=diff(y,2)./diff(t).^2
As far as I can see, your approximation is based on the assumption, that Z is equidistant. This is neither the general case, nor does it match the question. Therefore I think, that this approximation in unnecessarily rough, especially if the 2nd derivative is wanted.
Your method, cropped edges:
d2 = [-0.0826, 0.1385, -0.0413, -0.2079]
Suggest 2nd order method, one-sided differences at the edges:
d2 = [-0.0912, -0.0563, 0.0126, -0.0555, -0.1354, -0.1116]
Azzi Abdelmalek
on 2 Dec 2012
No, even Z is not equidistant, there is no reason that diff(Z) will change at each point, we are not looking for the variation of Z, it's No2. if the approximation is bad, it's because the distance between Z's value is big. To improve the result, maybe we can interpolate.
Image Analyst
on 30 Nov 2012
0 votes
How about the gradient() function?
Jan
on 1 Dec 2012
0 votes
Matlab's GRADIENT is accurate in the fist order only for not equidistant input. See FEX: DGradient and FEX: central_difference.
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!