How to Graph more than one ODE on a plot

15 ビュー (過去 30 日間)
Will Jeter
Will Jeter 2020 年 11 月 4 日
回答済み: Reshma Nerella 2020 年 11 月 10 日
I can't get my two functions for my ODEs to graph on the same plot. I'm not sure how get these to work with each other.
Volume = [0,2500];
Conversion = [0];
[V, X] = ode45(@odefun3,Volume,Conversion);
figure
plot(V,X)
xlabel('Volume')
ylabel('Conversion')
legend('No Inlet','Medium Inlet')
function dXdV = odefun3(V,X)
CA0 = 2/0.082/1100;
CI0 = CA0;
Theta = 0;
FA0 = 10;
CA01 = (CA0+CI0)/(Theta+1);
e = 1/(1+Theta);
T0 = 1100;
dHrx = 80000;
CpA = 170;
CpI = 200;
T = (X*(-dHrx)+(CpA+Theta*CpI)*T0)/(CpA+Theta*CpI);
k = exp(34.34-(34222/T));
ra = -k*CA01*(1-X)*T0/(1+e*X)/T;
dXdV = -ra/FA0;
end
[V, X] = ode45(@odefun4,Volume,Conversion);
function dXdV = odefun4(V,X)
CA0 = 2/0.082/1100;
CI0 = CA0;
Theta = 0.1;
FA0 = 10;
CA01 = (CA0+CI0)/(Theta+1);
e = 1/(1+Theta);
T0 = 1100;
dHrx = 80000;
CpA = 170;
CpI = 200;
T = (X*(-dHrx)+(CpA+Theta*CpI)*T0)/(CpA+Theta*CpI);
k = exp(34.34-(34222/T));
ra = -k*CA01*(1-X)*T0/(1+e*X)/T;
dXdV = -ra/FA0;
end

回答 (1 件)

Reshma Nerella
Reshma Nerella 2020 年 11 月 10 日
Hi,
As per my understanding, you want to plot 2 ODEs on same graph. Use can use hold command to add many plots on existing axes.
You can do it this way:
[V, X] = ode45(@odefun3,Volume,Conversion);
plot(V,X);
xlabel('Volume');
ylabel('Conversion');
hold on % to add new plot to same axes
[V, X] = ode45(@odefun4,Volume,Conversion);
plot(V,X);
xlabel('Volume');
ylabel('Conversion');
hold off % to prevent other plots using the same axes
legend('No Inlet','Medium Inlet'); % You can add legends for the plots at a time.
Hope this helps!

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by