Phase Portrait with Solution Curves

조회 수: 18 (최근 30일)
Abdullah Md Saifee
Abdullah Md Saifee 2017년 10월 27일
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.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by