How to add trajectory into a phase plane?

Hi, I have the code below of my function phase plane and it works fine. I want to add some trajectories into my phase plane, how am I able to do it?
function my_phase()
[~,X] = ode45(@EOM,[0 50],[1 1]);
u = X(:,1);
w = X(:,2);
plot(u,w)
xlabel('u')
ylabel('w')
grid
end
function dX = EOM(t, y)
dX = zeros(2,1);
u = y(1);
w = y(2);
A = 1;
B = 1;
dX = [w*u^2 - B*u;...
A - w - w*u^2];
end
It is my original phase plane
And I want my phase plane like this:
%

 채택된 답변

Mischa Kim
Mischa Kim 2014년 2월 24일
편집: Mischa Kim 2014년 2월 24일

0 개 추천

Like this?
function my_phase()
IC = [1 1; 1 2;1 3;1 4];
hold on
for ii = 1:length(IC(:,1))
[~,X] = ode45(@EOM,[0 50],IC(ii,:));
u = X(:,1);
w = X(:,2);
plot(u,w,'r')
end
xlabel('u')
ylabel('w')
grid
end
function dX = EOM(t, y)
dX = zeros(2,1);
u = y(1);
w = y(2);
A = 1;
B = 1;
dX = [w*u^2 - B*u;...
A - w - w*u^2];
end

댓글 수: 3

Alex
Alex 2014년 2월 24일
Hey there again, um, it seems not working correctly this time.
Mischa Kim
Mischa Kim 2014년 2월 24일
편집: Mischa Kim 2014년 2월 24일
What do you mean by not working correctly? Do you get an error msg, or, the plot does not look like the one you posted for the simple harmonic oscillator?
You only replace the first function, keep the second. See above.
Alex
Alex 2014년 3월 11일
Hey is me again, I have successfully to plot the graph, but it seems like the graph only shows the positive value, and I wonder can the trajectories toward to negative as well. Also I wonder how to add those blue arrow in my phase plane?

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sundas Mustafa
Sundas Mustafa 2015년 3월 13일

1 개 추천

use Quiver command for phase portrait. educ.jmu.edu/~strawbem/Phase_how_to.pdf
Xiwen Yuan
Xiwen Yuan 2014년 11월 5일
편집: Xiwen Yuan 2014년 11월 5일

0 개 추천

Hey, i have another answer to replace the first function with the following
function my_phase()
IC = [1 1; 1 2;1 3;1 4];
hold on
for ii = 1:length(IC(:,1))
[~,X] = ode45(@EOM,[0 50],IC(ii,:));
u = X(:,1);
w = X(:,2);
plot(u,w,'r')
u = gradient(X(:,1));
v = gradient(X(:,2));
quiver(X(:,1),X(:,2),u,v);
end
xlabel('u')
ylabel('w')
grid
end
%

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2014년 2월 24일

답변:

2015년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by