Function with different parameters
조회 수: 10 (최근 30일)
이전 댓글 표시
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
2018년 12월 16일
편집: madhan ravi
2018년 12월 16일
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
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
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!