The phase portrait of a second order of nonlinear system using matlab

6.3k Views Asked by At

I have the following system $$ \ddot{x} + 0.6\dot{x} + 3x + x^{2} = 0 $$

In the book I'm reading, the phase portrait of the nonlinear system for the aforementioned equation is

enter image description here

I would like to get same result in Matlab. This is what I did

function output = F(t, x)

output = [ x(2);
          -0.6*x(2) - 3*x(1) - x(1)^2];

end

and this is the main function

clear all
clc
   x0 = 1;
xdot0 = 1;
t = 0:0.01:10;
X0    = [x0, xdot0];

[T X] = ode45(@F, t, X0);


figure(1)
clf
plot(X(:,1), X(:,2))
title('The Phase Portrait of a nonlinear system');
xlabel('x');
ylabel('xdot');

I'm not getting same result. My question is how can I modify the code to get same result?


Edit: Now it is working with the following code.

function output = F(t, x)

output = [ x(2);
          -0.6*x(2) - 3.*x(1) - x(1)^2];

end

The main.m

t = 0:0.1:8;
X0    = [-3, 4.5];
[T X] = ode45(@F, t, X0);


figure(1)
clf

plot(X(:,1), X(:,2))
title('The Phase Portrait of a nonlinear system');
xlabel('x');
ylabel('xdot');
axis([-9 9 -10 10])
grid on

hold on
X0    = [4, 8];
[T X] = ode45(@F, t, X0);
plot(X(:,1), X(:,2))

hold on
X0    = [-1, 2];
[T X] = ode45(@F, t, X0);
plot(X(:,1), X(:,2))

hold on
X0    = [-7, 6];
[T X] = ode45(@F, t, X0);
plot(X(:,1), X(:,2))

hold on
X0    = [-8, 5];
[T X] = ode45(@F, t, X0);
plot(X(:,1), X(:,2))

hold on
X0    = [-5.5, 9];
[T X] = ode45(@F, t, X0);
plot(X(:,1), X(:,2))

hold on
X0    = [-2.5, 8];
[T X] = ode45(@F, t, X0);
plot(X(:,1), X(:,2))