
Plotting third order differential equation using ode45
2 次查看(过去 30 天)
显示 更早的评论
Hello
Could you please how to plot below third order differential equation using ODE45.
d3x/dt3 = +-1
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!