Plotting phase space for 2nd order nonlinear ODE
14 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Star Strider
on 9 May 2022
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'})
% Function Definition
function [x_primes] = ODE45SolvMain(t,x)
u = 1;
x_primes = [x(2); u*((1-x(1)^2))*x(2)-x(1)];
end
.
0 Comments
More Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!