How can I plot a graph by varying two parameters a and b in system of ODE at the same time?

4 次查看(过去 30 天)
How can I plot a graph by varying two parameters say a and b in the system of ordinary differential equations given below at the same time so that the first line of solution will be when a=1, b=2, the second line of solution will be when a=2, b=3, the third line of solution will be when a=3, b=4 and I will have three lines of solutions on the same graph? I want to plot t against
function SYSTEM1ODE ()
global C a b d e g
clear all
clc
tspan=[0 5];
a=1;d=2;C=10000;e=5;g=1;
for b= 2:1:4
[t,x]=ode45(@modmat, tspan, [1200;1150;1000])
plot(t,x(:,2),'linewidth',1.5)
xlabel('Time (Days)'),ylabel('Amonut (X_2)')
hold on
end
function xprime = modmat(t,x)
xprime=[0;0;0];
xprime(1)=C-a*x(1)-b*x(2)+d*x(1);
xprime(2)=a*x(1)-b*x(2)-(d+e)*x(2);
xprime(3)=e*x(2)-g*x(3);
end
end
How can I add 'a' to it, so that 'a' and 'b' will be varying at the same time and still get three lines of solutions on the same graph?
  2 个评论
Torsten
Torsten 2024-2-25
Can you include the code for a single combination ? We will show you how to make a loop to use it three times.
SAHEED AJAO
SAHEED AJAO 2024-2-25
Thanks, I can only vary one variable 'b' alone but unable to vary the two at the same time. Here is the code.
function SYSTEM1ODE ()
global C a b d e g
clear all
clc
tspan=[0 5];
a=1;d=2;C=10000;e=5;g=1;
for b= 2:1:4
[t,x]=ode45(@modmat, tspan, [1200;1150;1000])
plot(t,x(:,2),'linewidth',1.5)
xlabel('Time (Days)'),ylabel('Amonut (X_2)')
hold on
end
function xprime = modmat(t,x)
xprime=[0;0;0];
xprime(1)=C-a*x(1)-b*x(2)+d*x(1);
xprime(2)=a*x(1)-b*x(2)-(d+e)*x(2);
xprime(3)=e*x(2)-g*x(3);
end
end
How can I add 'a' to it, so that 'a' and 'b' will be varying at the same time and still get three lines of solutions on the same graph?

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2024-2-26
编辑:Torsten 2024-2-26
A = [1;2;3];
B = [2;3;4];
C = 10000;
d = 2;
e = 5;
g = 1;
tspan = [0 5];
for i = 1:numel(A)
a = A(i);
b = B(i);
[t,x] = ode45(@(t,x)modmat(t,x,a,b,C,d,e,g),tspan,[1200;1150;1000]);
plot(t,x(:,2),'linewidth',1.5)
xlabel('Time (Days)'),ylabel('Amonut (X_2)')
hold on
end
function xprime = modmat(t,x,a,b,C,d,e,g)
xprime=[0;0;0];
xprime(1)=C-a*x(1)-b*x(2)+d*x(1);
xprime(2)=a*x(1)+b*x(2)-(d+e)*x(2);
xprime(3)=e*x(2)-g*x(3);
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by