Plotting phase space for 2nd order nonlinear ODE

4 ビュー (過去 30 日間)
Fue Xiong
Fue Xiong 2022 年 5 月 9 日
回答済み: Steven Lord 2022 年 5 月 9 日
Hello, I'm trying to figure out how to plot the phase space for a 2nd order nonlinear ODE.
Problem Statement
Given the 2nd order ODE, (d^2x/dt^2) - u*(1-x^2)*(dx/dt)+x=0, initial conditions are x(0) = 2 and x'(0) = 0. Find the solution if u = 1 and t is from 0-30 seconds. Plot time vs x and the phase space where x vs x'
MATLAB Code (what I have so far)
[t, y] = ode45(@ODE45SolvMain,[0 30],[2 0])
figure(1)
plot(t,y(:,1),t,y(:,2))
xlabel('Time t')
ylabel('Displacement')
title('Displacement vs Time')
legend('x_1','x_2')
---------------------------------------------------------
% Function Definition
function [x_primes] = ODE45SolvMain(t,x)
u = 1;
x_primes = [x(2); u*((1-x(1)^2))*x(2)-x(1)]
My solution so far
This figure is for the time vs x plot. I am unsure how to begin and plot the phase space for the this ODE.

採用された回答

Star Strider
Star Strider 2022 年 5 月 9 日
I am not certain what you want to plot for the phase plot.
This calculates and plots as a funciton of and also calculates the derivatives (as the ‘derivs’ matrix) in the event those are also to be plotted —
[t, y] = ode45(@ODE45SolvMain,[0 30],[2 0]);
figure(1)
plot(t,y(:,1),t,y(:,2))
xlabel('Time t')
ylabel('Displacement')
title('Displacement vs Time')
legend('x_1','x_2')
figure(2)
plot(y(:,1),y(:,2))
xlabel('x_1')
% xlabel(']Time t')
ylabel('x_2')
% ylabel('Displacement')
title('Phase')
% legend('x_1','x_2')
% Derivative Calculations
for k = 1:numel(t)
derivs(k,:) = ODE45SolvMain(t(k),y(k,:));
end
Derivs = table(t,derivs(:,1),derivs(:,2), 'VariableNames',{'t','dy1dt','dy2dt'})
Derivs = 341×3 table
t dy1dt dy2dt __________ ___________ _______ 0 0 -2 2.5119e-05 -5.0236e-05 -1.9998 5.0238e-05 -0.00010047 -1.9997 7.5357e-05 -0.0001507 -1.9995 0.00010048 -0.00020092 -1.9994 0.00022607 -0.00045199 -1.9986 0.00035166 -0.00070296 -1.9979 0.00047726 -0.00095383 -1.9971 0.00060285 -0.0012046 -1.9964 0.0012308 -0.0024571 -1.9926 0.0018588 -0.0037072 -1.9889 0.0024868 -0.004955 -1.9851 0.0031147 -0.0062005 -1.9814 0.0062546 -0.012392 -1.9628 0.0093945 -0.018526 -1.9443 0.012534 -0.024603 -1.9261
% Function Definition
function [x_primes] = ODE45SolvMain(t,x)
u = 1;
x_primes = [x(2); u*((1-x(1)^2))*x(2)-x(1)];
end
.

その他の回答 (1 件)

Steven Lord
Steven Lord 2022 年 5 月 9 日
See this Answers post for an example that sounds like what you want to do.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by