How to have multiple lines on a graph for different values of a parameter.

19 ビュー (過去 30 日間)
Westin Messer
Westin Messer 2018 年 11 月 6 日
編集済み: madhan ravi 2018 年 11 月 6 日
Hello,
I'm trying to vary the parameter 'k' from 0 to 4 in this code. However, there is an error because the blue lines in the plot should not be shooting out to the right. Can anyone see what I am doing wrong?
Thanks!
%Clear command window and workspace
clear
close all
clc
% Fitzhugh-Nagoma model parameters
e=0.01; k=1:1:4; a=0.1;
i = 0.001;
figure(1);
hold on
u=zeros(500000,4);
v=zeros(500000,4);
t=zeros(100000,1);
% Initial conditions:
u(:)=0.6;
v(:)=0.0;
t(1)=0;
dt=0.001;
%==========================================================================
% Forvard Euler Method, for soluing the ODE
%==========================================================================
for i=1:1:500000
t(i+1)=t(i)+dt;
% u(i+1) = u(i)+ dt*((1/e)*((k(:)*u(i)*(u(i)-a)*(1-u(i)))-v(i)));
u(i+1,:) = u(i,:)+ dt*((1/e)*((k*(u(i,:)*(u(i,:)-a)*(1-u(i,:))))-v(i)));
v(i+1,:) = v(i,:)+ dt*(u(i)-v(i));
end
% Getting the phase plot
figure(1);
upts=(-2:.05:2);
unullpts=(k(:)*upts.*(upts-a).*(1-upts));
vnullpts=upts;
plot(upts,unullpts,'black',upts,vnullpts,'black');
xlabel('u'); ylabel('v');
axis([-1 2 -1.5 5]);
plot(u,v,'b')
title('Nullcline Plot')
xlabel('u')
ylabel('v')

採用された回答

madhan ravi
madhan ravi 2018 年 11 月 6 日
編集済み: madhan ravi 2018 年 11 月 6 日
EDITED
%Clear command window and workspace
clear
close all
clc
% Fitzhugh-Nagoma model parameters
e=0.01;
k=1:1:4; a=0.1;
i = 0.001;
figure(1);
hold on
u=zeros(500000,4);
v=zeros(500000,4);
t=zeros(100000,1);
% Initial conditions:
u(:)=0.6;
v(:)=0.0;
t(1)=0;
dt=0.001;
%==========================================================================
% Forvard Euler Method, for soluing the ODE
%==========================================================================
for i=1:1:500000
t(i+1)=t(i)+dt;
% u(i+1) = u(i)+ dt*((1/e)*((k(:)*u(i)*(u(i)-a)*(1-u(i)))-v(i)));
u(i+1,:) = u(i,:)+ dt.*((1/e).*((k.*(u(i,:).*(u(i,:)-a).*(1-u(i,:))))-v(i)));
v(i+1,:) = v(i,:)+ dt.*(u(i)-v(i));
end
% Getting the phase plot
figure(1);
upts=(-2:.05:2);
unullpts=(k(1).*upts.*(upts-a).*(1-upts));
vnullpts=upts;
plot(upts,unullpts,'black',upts,vnullpts,'black');
axis([-1 2 -1.5 5]);
hold on
plot(-u,-v,'b')
unullpts=(k(2).*upts.*(upts-a).*(1-upts));
vnullpts=upts;
plot(upts,unullpts,'m');
unullpts=(k(3).*upts.*(upts-a).*(1-upts));
vnullpts=upts;
plot(upts,unullpts,'r');
unullpts=(k(4).*upts.*(upts-a).*(1-upts));
vnullpts=upts;
plot(upts,unullpts,'g');
title('Nullcline Plot')
xlabel('u')
ylabel('v')
  11 件のコメント
Westin Messer
Westin Messer 2018 年 11 月 6 日
Thanks. Is there any way I can put that in some kind of loop? For example, if I wanted to do 20 different values of k I wouldn't have to write the plot line 20 times.
madhan ravi
madhan ravi 2018 年 11 月 6 日
編集済み: madhan ravi 2018 年 11 月 6 日
for i = 1:numel(k)
unullpts=(k(i).*upts.*(upts-a).*(1-upts));
vnullpts=upts;
plot(upts,unullpts,'m');
hold on
end
The above does the same work what you want

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by