graphical representation with (x, y) in Matlab

91 Views Asked by At

I need to plot a graph of system differential equation in Matlab. I am new in this program. $$ \begin{cases} \dot x=2*x+y \\ \dot y=2*(x^2-1)*x \end{cases}$$

This system in nonlinear and functions in Matlab as "quiver" don't help me and there are three equilibrium points. There are one focus and two saddles. I didn't find any useful information in the internet. Thanks for the help. Sorry for my English!

1

There are 1 best solutions below

6
On BEST ANSWER

Here is a Matlab program that does the job :

function main
clear all;close all,hold on;set(gcf,'color','w');
axis equal;axis([-2,2,-2,2]);
set(gcf,'color','w');
ts = -2:0.01:2; % time range
s = @(t,V) S(V); % take care : s and S
for k=-1:0.1:1
   V0= [0;k]; % column vector : initial point (arbitrarily) chosen on the y-axis  
   [t,V] = ode45(s, ts, V0);  
   plot(V(:,1),V(:,2)); 
end;
%
function der = S(x) ; % RHS of the differential system 
xp1=2*x(1)+ x(2);
xp2=2*(x(1).^2-1).*x(1);
der=[xp1;xp2]; 

with the result displayed on the figure.

How can we check the obtained curves ? For example, on the curves situated on the right, one sees that the slope is negative, resp. positive for values of $x$ that are $<1$, resp. $>1$. This is easily explainable with the sign of the following expression

$$\dfrac{dy}{dx}=\dfrac{dy:dt}{dx/dt}=\dfrac{\dot y}{\dot x}=\frac{2(x^2-1)x}{2x+y}$$

The $(x^2-1)$ factor being "entirely responsible" for the change of sign in the area $x>0$ and $y>0$. But a complementary fact brings new light : the change of sign at the boundary given by the transition

If one day, you want to visualize the phase portrait, for example of $x$, i.e. work with generalized coordinates $(x,\dot x)$, plainly

  • replace (10 th line) "plot V(:,1),V(:,2)" by "plot V(:,1),2*V(:,1)+V(:,2)" (by reference to equation $\dot x=2x+y$)

  • replace V0=[0;k] (8 th line) for example by V0=0.2*(rand(2,1)-0.1.

enter image description here