Solving and plotting ode's in matlab
Ältere Kommentare anzeigen
%reaction data
E1=42; % forward activation energy
Cn2=1; % feed concentration
R =8.314;
A1=.04;
A2=.1;
Co2=1;
Fa0= Cn2 + Co2;
T0=500 ; % feed temperature
Cpn2 =29.7198; Cpo2=29.051; Cpno =29.3018; %j/mol.K
deltaCp = 2*Cpno-Cpo2-Cpno;
Hrxn = 180.5; % kj/mol at refrence temp 300K
Ua =0.01;
Ta0 =550;
mc = 0.011
Cpc= 34.5
syms X(V) T(V) Ta(V)
ra = -A1*exp(-E1/(8.314*T))*(Cn2^2)*((1-X)^2)*((T0/T)^2);
eqn1 = diff(X, V) == ra/Fa0; %X
eqn2 = diff(T, V) == (Ua*(Ta-T)+ra*Hrxn)/(Fa0*(Cn2*Cpn2+Co2*Cpo2)); %T
eqn3 = diff(Ta, V) == Ua*(Ta-T)/(mc*Cpc);
[odes, vars] = odeToVectorField(eqn1, eqn2, eqn3);
fun = matlabFunction(odes,'Vars',{'t','Y'});
x0 = [0 500 550 ];
tspan = [0 550];
[t, sol] = ode45(fun,tspan,x0);
X = sol(:,1);
T = sol(:,2);
Ta = sol(:,3);
plot(t,sol(:,1))
hold
grid
title('X vs Volume')
xlabel('Volume')
ylabel('X')
hold off
plot(t,sol(:,2),t,sol(:,3)) %plotting Ta on same graph
hold
grid
title('T vs Volume')
xlabel('Volume')
ylabel('T')
hold off
for i = 1:501
Ra(i) = Fa0*(sol(i,2)/t(i,1));
plot(t,Ra)
hold
grid
title('-ra vs V')
xlabel('Volume')
ylabel('-ra')
hold off
end
- This is my new code. Although i think i properly indexed everything the output is not as expected.
- Except the initialized values all values of sol array is NaN for some reason.

6 Kommentare
Walter Roberson
am 3 Dez. 2021
We need all of your code in text form in order to test it ourselves.
[Vv,Yv]=ode45('varT',[0:500],[0;500]);
That is two initial conditions. You cannot have 3 outputs for two initial conditions.
Sujay Bharadwaj
am 3 Dez. 2021
Bearbeitet: Sujay Bharadwaj
am 3 Dez. 2021
Sujay Bharadwaj
am 3 Dez. 2021
Walter Roberson
am 3 Dez. 2021
You must pass in one initial condition for each output -- you need 
Sujay Bharadwaj
am 3 Dez. 2021
Sujay Bharadwaj
am 3 Dez. 2021
Antworten (0)
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!