MATLAB Answers


Taking the second derivative

Hans123 님이 질문을 제출함. 7 Feb 2019
최근 활동 Torsten 님이 편집함. 11 Feb 2019
I have two arrays M and V, both are the same dimesions.
I am trying to find and plot this vs. M, this is the code I am working with - but it doesn't work - what should I do?
second_der = diff(V_preamp,2)./diff(M,2);
The probem with the above code is it creates a second derivative code that is shorter than the independent variable I am plotting the graph with (independent variable - M)
How can I fix this isse.

  댓글 수: 0

로그인 to comment.




답변 수: 1

Answer by Torsten
on 7 Feb 2019
Edited by Torsten
on 8 Feb 2019
 Accepted Answer

second_der = zeros(size(V_preamp));
second_der(2:end-1) = ((V_preamp(3:end)-V_preamp(2:end-1))./...

  댓글 수: 4

표시 이전 댓글 수: 1
on 8 Feb 2019
Code corrected.
Best wishes
Hans123 on 9 Feb 2019
Thanks a lot, it works - If I may ask, how did you get the equation to find the second derivative?
on 11 Feb 2019
It's the usual finite difference approximation for the second derivative.
On uniform grids,
f''(x_i) = (approximately) (f(x_i-h)-2*f(x_i)+f(x_i+h))/h^2
On non-uniform grids
f''(x_i) = (approximately) ((f(x_(i+1)-f(x_i)))/(x_(i+1)-x_i) - (f(x_i)-f(x_(i-1)))/(x_i-x_(i-1)))/(0.5*(x_(i+1)-x_(i-1)))

로그인 to comment.

Translated by