How can I plot a graph by varying two parameters a and b in system of ODE at the same time?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Torsten
le 25 Fév 2024
Can you include the code for a single combination ? We will show you how to make a loop to use it three times.
Réponse acceptée
Torsten
le 26 Fév 2024
Modifié(e) : Torsten
le 26 Fév 2024
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!