Plotting third order differential equation using ode45

조회 수: 2 (최근 30일)
vaibhav gupta
vaibhav gupta 2020년 12월 6일
댓글: Ameer Hamza 2020년 12월 7일
Hello
Could you please how to plot below third order differential equation using ODE45.
d3x/dt3 = +-1

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 12월 6일
편집: Ameer Hamza 2020년 12월 6일
You need to convert this 3-rd order ODE to 3 first order ODEs. Also due to +-1, you have two systems of ODEs. Try following code
odeFun = @(t,x,a) [x(2);
x(3);
a];
tspan = [0 10];
IC = [1; 0; 0];
ode45(@(t,x) odeFun(t,x,1), tspan, IC)
hold on
ode45(@(t,x) odeFun(t,x,-1), tspan, IC)
legend({'$x$', '$\dot{x}$', '$\ddot{x}$'}, 'Interpreter', 'latex', 'FontSize', 16, ...
'Location', 'best')
  댓글 수: 2
vaibhav gupta
vaibhav gupta 2020년 12월 6일
편집: vaibhav gupta 2020년 12월 6일
Thank you! I just wanted to plot result of first ode. How can i supress rest? Also, i see that plot is continuing and not stopping at all. Shoudln't it be stopped rendering at some point of time?
Ameer Hamza
Ameer Hamza 2020년 12월 7일
Try this
odeFun = @(t,x,a) [x(2);
x(3);
a];
tspan = [0 10];
IC = [1; 0; 0];
[t, y] = ode45(@(t,x) odeFun(t,x,1), tspan, IC);
plot(t, y(:,1))
hold on
[t, y] = ode45(@(t,x) odeFun(t,x,-1), tspan, IC);
plot(t, y(:,1))
legend({'$+1$', '$-1$'}, ...
'Interpreter', 'latex', ...
'FontSize', 16, ...
'Location', 'best')

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by