How to add trajectory into a phase plane?
16 ビュー (過去 30 日間)
古いコメントを表示
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157493/image.bmp)
And I want my phase plane like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157495/image.png)
%
0 件のコメント
採用された回答
Mischa Kim
2014 年 2 月 24 日
編集済み: Mischa Kim
2014 年 2 月 24 日
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 件のコメント
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.
その他の回答 (2 件)
Sundas Mustafa
2015 年 3 月 13 日
use Quiver command for phase portrait. educ.jmu.edu/~strawbem/Phase_how_to.pdf
0 件のコメント
Xiwen Yuan
2014 年 11 月 5 日
編集済み: Xiwen Yuan
2014 年 11 月 5 日
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176492/image.png)
%
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!