# How to plot this phase portrait correctly?

32 views (last 30 days)
Levente Kis on 26 Apr 2020
Commented: Ameer Hamza on 26 Apr 2020
The following ODE describes a nonlinear mechanical system:
where are numerically given system parameters.
I have to plot the phase portrait of this ODE. I tried the following:
I tried the following code:
clear all;
clc;
%data:
l=0.1;
a=0.06;
m=1;
s=1200;
[x,y]=meshgrid(-0.12:.0005:0.12, -0.12:.0005:0.12);
dx=y;
dy=-(s/m)*x.*(1-l*(sqrt(x.^2+a^2))).^(-1);
streamslice(x,y,dx,dy);
title('Phase portrait')
axis tight equal
The system has 3 equilibrium points: in (0;0) there is a saddle, in (0.08;0) there is a centre, and in (-0.08;0) there is also a centre. So the phase portrait should look like the following:
Yet, Matlab gives me the following:
This isn't look good. What could be the problem, and how should I fix my code, to get a better result?

Ameer Hamza on 26 Apr 2020
You wrote the equation for dy wrong. Also, the range of y-values is also small. Try this
clear all;
clc;
%data:
l=0.1;
a=0.06;
m=1;
s=1200;
[x,y]=meshgrid(-0.12:0.01:0.12, -1:0.2:1);
dx = y;
dy = -(s/m)*x.*(1-l./sqrt(x.^2+a^2));
streamslice(x, y, dx, dy, 'filled');
title('Phase portrait')
axis tight
##### 2 CommentsShowHide 1 older comment
Ameer Hamza on 26 Apr 2020
You can try quiver instead of streamslice. For example,
clear all;
clc;
%data:
l=0.1;
a=0.06;
m=1;
s=1200;
[x,y]=meshgrid(-0.15:0.01:0.15, -1:0.2:1);
dx = y;
dy = -(s/m)*x.*(1-l./sqrt(x.^2+a^2));
streamslice(x, y, dx, dy);
% hold on
quiver(x, y, dx, dy);
title('Phase portrait')
axis tight