How to use ode45 with a time dependant second order differential equation

조회 수: 1 (최근 30일)
curiously learning
curiously learning 2021년 6월 16일
댓글: Alan Stevens 2021년 6월 17일
Hello,
I have the below code for a second order ordinary differential equation. In this, the value of D depends on y (as shown by the commented line). I see from the Matlab help file for ode45, how such an equation be solved for a first order. But I don't know how to do it for a second order equation. Could you please help? Thank you.
syms h(t)
A=10*diff(h, 2);
B=8 * diff(h) ;
C=10 * h ;
%D=interp1(E(:,1),E(:,2),y)
D=2; %[
[V] = odeToVectorField(A == (D-C-B));
M = matlabFunction(V,'vars', {'t','Y'});
sol = ode45(M,[0 10],[0 0]);
fplot(@(x)deval(sol,x,1), [0, 10]);

답변 (1개)

Alan Stevens
Alan Stevens 2021년 6월 17일
Turn your second order equation into two simultaneous first order equations.
  댓글 수: 2
curiously learning
curiously learning 2021년 6월 17일
Thank you for the suggestion. That is where I am struggling. To convert, one has to use a odetovectorfield, and I don't know how to use it in this context. Could you perhaps give an example?
Alan Stevens
Alan Stevens 2021년 6월 17일
If you are interested only in numerical results you don't need any symbolic stuff at all.
With an equation like d^2y/dt^2 + a*dy/dt + b*y = 0, you can turn that into two first order equations bysetting
dy/dt = v
dv/dt = -a*v - b*y
Do
doc ode45
for more details.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by