Plotting the solution to a system of second order differential equations

1 回表示 (過去 30 日間)
Aleem Andrew
Aleem Andrew 2020 年 4 月 3 日
コメント済み: Aleem Andrew 2020 年 4 月 3 日
I am having difficulty interpreting the plots generated by the following code. Is there a way I can generate a single plot instead of four plots, for example, the plot of θ(t) vs x(t)?
ode = @fun;
t = [0 10];
ic = [pi/3; 0; 0; 0]; % [θ θ' x x']
[t,x] = ode45(ode, t, ic);
plot(t,x);
xlabel('x(t)');
ylabel('θ(t)');
function dydx = fun(t,x)
L = 0.5; g = 9.81;
dydx = zeros(4,1);
dydx(1) = x(2);
dydx(2) = (4*sin(x(1))*(5*L*cos(x(1))*x(2)^2 + 6*g))/(L*(20*cos(x(1))^2 - 23));
dydx(3) = x(4);
dydx(4) = -(5*sin(x(1))*(23*L*x(2)^2 + 24*g*cos(x(1))))/(6*(20*cos(x(1))^2 - 23));
end
The code generates four plots, only one of which satisfies the initial conditions (θ = pi/3 and x = 0) while I do not understand what the other plots represent.

採用された回答

Birdman
Birdman 2020 年 4 月 3 日
Is there a way I can generate a single plot instead of four plots, for example, the plot of θ(t) vs x(t)?
Yes you can, with the following line:
plot(t,x(:,1))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by