0

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!

GIFT
  • 321

1 Answers1

1

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

Jean Marie
  • 81,803
  • As you have seen, I have taken initial points on $y$ axis now : the understanding of solutions is easier in this way. Does it answers your question ? – Jean Marie Feb 27 '20 at 12:39
  • yes, thank you for your answer! – GIFT Feb 27 '20 at 13:20
  • If this answer is a complete solution for you, think to check it. I have had a look at your profile : you haven't checked any of the answers you have received... some of them a long time ago. – Jean Marie Feb 27 '20 at 17:39
  • I always check it by myself or should I write about it here? – GIFT Feb 29 '20 at 10:14
  • No, i didn't meant "check = verifying". What I was saying is that on the upper left hand side of answers you have a check sign (looking like a square root sign). Click on it to say you validate this answer as satisfying. This avoids a lot of further answers. – Jean Marie Feb 29 '20 at 10:18
  • Otherwise, if you praise a solution but think that there should be coming improved ones, click on the "up" button to increase the "good answer" status. – Jean Marie Feb 29 '20 at 10:24