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.

 채택된 답변

Torsten
Torsten 2019년 2월 7일
편집: Torsten 2019년 2월 8일

2 개 추천

second_der = zeros(size(V_preamp));
second_der(2:end-1) = ((V_preamp(3:end)-V_preamp(2:end-1))./...
(M(3:end)-M(2:end-1))-...
(V_preamp(2:end-1)-V_preamp(1:end-2))./...
(M(2:end-1)-M(1:end-2)))./...
(0.5*(M(3:end)-M(1:end-2)));
plot(M(2:end-1),second_der(2:end-1))

댓글 수: 5

Hans123
Hans123 2019년 2월 7일
Hi Torsten,
Thanks for that answer! I get a matrix dimensions don't agree error.
Can you tell me how you got the second derivative?
Torsten
Torsten 2019년 2월 8일
Code corrected.
Best wishes
Torsten.
Hans123
Hans123 2019년 2월 9일
Thanks a lot, it works - If I may ask, how did you get the equation to find the second derivative?
Torsten
Torsten 2019년 2월 11일
편집: Torsten 2019년 2월 11일
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)))
David Kohlisa
David Kohlisa 2021년 3월 2일
For the two arrays V and M you have, V must be equal to some function of M where V = f(M).
To get the second derivative of V with respect to M it is simply:
d2VdM2 = diff(V, M, 2)
where V=f(M), M is what you differentiating with respect to and 2 is order of the derivative.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

2019년 2월 7일

댓글:

2021년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by