Phase Portrait with Solution Curves

9 Ansichten (letzte 30 Tage)
Abdullah Md Saifee
Abdullah Md Saifee am 27 Okt. 2017
So i was trying to solve the following system of differential equation and its phase portrait. x'=x y'=-y According to this page http://matlab.cheme.cmu.edu/2011/08/09/phase-portraits-of-a-system-of-odes/ I wrote the following
f=@(t,X)[X(1); -X(2)];
x1=linspace(-5,5,20);
x2=linspace(-5,5,20);
[x y]=meshgrid(x1,x2);
size(x)
size(y)
u=zeros(size(x));
v=zeros(size(x));
t=0;
for i=1:numel(x)
Xprime=f(t,[x(i); y(i)]);
u(i)=Xprime(1);
v(i)=Xprime(2);
end
quiver(x,y,u,v,'k');figure(gcf)
xlabel('x_1')
ylabel('x_2')
axis tight equal;
hold on
for i=-5:1:5
for x20=[-5 5]
if (-5<i & i<5 & -5<x20 & x20<5)
continue
end
[ts xs]=ode45(f,[0 50],[0;x20]);
plot(xs(:,1),xs(:,2))
%plot(xs(1,1),xs(1,2),'ko')
%plot(xs(end,1),xs(end,2),'ks')
end
end
hold off
This gives me its phase portrait ONLY. As sson as I replace "0" in the solution vector input in [ts xs]=ode45(f,[0 50],[0;x20]) with "i" to get multiple solution curves, it does not give me proper answer. What am I doing wrong here? p.s.: The equilibrium/critical point here is a saddle point.

Antworten (0)

Kategorien

Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by