Hi everyone,
I am trying to vary the parameter e =[0.0001,0.0005,0.001,0.005,0.01] in my function and want to plot it in one figure. how can I do it?
Thank you!!
Hier is my code:
% Main program
s0=1;
c0=0;
t=linspace(0,10,100);
x0=[s0 c0];
[t,x]=ode45(@(t,x) num_lsg1(t,x), t, x0);
plot(t,x(:,1),'-o',t, x(:,2),'-x')
xlabel('time [s]');
ylabel('Substrat, Complex');
legend('Substrat','Complex')
%%Function definition
function dx=num_lsg1(t,x)
% Parameters
kme=0.625;
e=0.001;
kmm=1;
dx=zeros(2,1);
dx(1)=kme*x(2)-x(1)*(1-x(2));
dx(2) = (x(1)*(1-x(2))-kmm*x(2))/e;
end

 採用された回答

madhan ravi
madhan ravi 2018 年 12 月 16 日
編集済み: madhan ravi 2018 年 12 月 16 日

0 投票

s0=1;
c0=0;
t=linspace(0,10,100);
x0=[s0 c0];
for e =[0.0001,0.0005,0.001,0.005,0.01]
[t,x]=ode45(@(t,x) num_lsg1(t,x,e), t, x0); % function call
figure
plot(t,x(:,1),'-o',t, x(:,2),'-x')
xlabel('time [s]');
ylabel('Substrat, Complex');
legend('Substrat','Complex')
end
%%Function definition
function dx=num_lsg1(t,x,e)
% Parameters
kme=0.625;
kmm=1;
dx=zeros(2,1);
dx(1)=kme*x(2)-x(1)*(1-x(2));
dx(2) = (x(1)*(1-x(2))-kmm*x(2))/e;
end
Note: If you dont want separate figures you can remove figure and put hold on after the plot command because if you plot them in the same figure all the plots look the same because e variation is so small,.

3 件のコメント

Tatjana Henning
Tatjana Henning 2018 年 12 月 16 日
編集済み: Tatjana Henning 2018 年 12 月 16 日
Hey, thank you so much for the fast answer (and the note!) again! It works.
I plotted it in the same figure. You can see the difference, wenn you plot between 0 and 0.01. :)
Now I tried to put 2 different dif.eq. and the difference between them in the same plot. Is my code ok? It works, but I am not sure, if it shows, what it should.
% 1
% Main program
s1=1;
t=linspace(0,10,100);
x0=[s1];
% 2
% Main program
s2=1;
c0=0;
t=linspace(0,10,100);
x00=[s2 c0];
[t,x1]=ode45(@(t,x1) num_lsg1(t,x1), t, x0);
[t,x2]=ode45(@(t,x2) num_lsg2(t,x2), t, x00);
%plot(t,x1(:,1),'-o ')
%hold on;
%plot(t,x2(:,1),'-o',t, x2(:,2),'-x')
%hold on;
plot(t,x1(:,1)-x2(:,1),'-* ')
xlabel('time [s]');
ylabel('Substrat');
legend('1','2','difference')
%%function 1
function dx1=num_lsg1(t,x1)
% parameters
kme=0.625;
kmm=1;
k=kmm-kme;
dx1=zeros(1,1);
dx1(1)=-(k*x1(1))/(kmm+x1(1));
end
%%function 2
function dx2=num_lsg2(t,x2)
% parameters
kme=0.625;
e=0.001;
kmm=1;
dx2=zeros(2,1);
dx2(1)=kme*x2(2)-x2(1)*(1-x2(2));
dx2(2) = (x2(1)*(1-x2(2))-kmm*x2(2))/e;
end
madhan ravi
madhan ravi 2018 年 12 月 17 日
Anytime :) ,
plot(t,x1(:,1),'-ok',t,x2(:,1),'-* ') % correct syntax
By the way I don't see the difference in the same plot it looks like they lie on each other anyway it's your wish.
University Glasgow
University Glasgow 2022 年 9 月 15 日
Hi please, how can plot for two different values of the varing parameters on the same figure. For instance, e= 0.0001 and e= 0.0005 on the same figure?

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by