Seeking help: the direction field are all vertical bars

1 回表示 (過去 30 日間)
ryecatcher
ryecatcher 2020 年 2 月 13 日
コメント済み: ryecatcher 2020 年 2 月 13 日
Dear All:
First of all, I am sorry for the newbie questions. I have googled everywhere, including you-tube, and still cannot get my direction field correctly.
I am trying to plot the direction field of this differential equation: dy/dt=y*(y-1)(y-2)
Clearly, there are 3 critical points. y=0 & 2 are unstable; y=1 is stable.
My code:
% y'=y(y-1)(y-2)
[T, Y]=meshgrid(-3:0.1:3, -3:0.1:3)
S=Y*(Y-1)*(Y-2);
L=sqrt(1+S.^2);
quiver(T, Y, 1./L, S./L, 0.3), axis tight
xlabel 't', ylabel 'y'
title 'Direction Field for dy/dt = y(y-1)(y-2)'
Below is what I got. I don't understand why most part are just vertical bars. I cannot see the trend at all. I have played with changing some parameters in the code and it still didn't come out nicely. Thank you very much for your help. I greatly appreciate it.

採用された回答

darova
darova 2020 年 2 月 13 日
YOu forgot the dot
S = Y.*(Y-1).*(Y-2);
Don't you forgot dt here?
L=sqrt(1+S.^2);
  1 件のコメント
ryecatcher
ryecatcher 2020 年 2 月 13 日
Dear Sir: Thank you very much for your reply! Following your suggestion, now it has worked. I have added dot at two places:
previous wrong code:
S=Y*(Y-1)*(Y-2);
Now, the correct working code:
S=Y.*(Y-1).*(Y-2);
Here is the direction field picture. y=0, 1 and 2 are equilibrium solutions. y=1 is stable

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVector Fields についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by