How can I plot a graph by varying two parameters a and b in system of ODE at the same time?
6 次查看(过去 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 ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1627218/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1627218/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1627263/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1627268/image.png)
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
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.
采纳的回答
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 Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!