How can I solve this differential equation?
Show older comments
Hello, I'm trying to solve the differential equation however, I have some problem during solving my problem.
clear, clc
format long
syms c1(t) rho_cat V a1 a2 a3 a4 c10 R T t
Eq1 = diff(c1) == (-(rho_cat / V) * a1* exp(-a2 / (R * (T+273.15))) * (c1^a3)) / (1+a4*c1);
[C1] = dsolve(Eq1,c1(0) == c10)
C1 = matlabFunction([C1], 'Vars',{[a1,a2,a3,a4],t,c10,rho_cat,V, R, T})
When I try to get c1 using dsolve, and define c1 as a matlab function, the matlab gets error with this message.
Warning: Function '_minus' not verified to be a valid MATLAB function.
Warning: Finite sets ('DOM_SET') not supported. Using element '0' instead.
I think the reason of warning is because C1 has a form like below when I use dsolve to get C1
solve([c1^(1 - a3)*(a3 - a4*c1 + a3*a4*c1 - 2) == ((c10*(a3 - a4*c10 + a3*a4*c10 - 2))/(c10^a3*(a3^2 - 3*a3 + 2)) + (a1*rho_cat*t*exp(-(20*a2)/(5463*R + 20*R*T)))/V)*(a3^2 - 3*a3 + 2), c1 ~= 0], c1) minus {0}
Do I have to use other method to solve this problem like ode45 or ode23 instead of dsolve?
I hope I can get a good reply.
Thanks.
1 Comment
Accepted Answer
More Answers (1)
function main
%% defining parameter
P = [80;120;100;80;120;80;120;100;80;120;80;80;100;120;100]; % Pressure, bar
T = [80;80;80;80;80;100;100;100;100;100;120;120;120;120;120]; % Temperature, C
t = 0.1; %reactor length 0.1m
R = 8.314 ; % gas constant J/mol*K
S = 0.001808; % cross-sectional area of reactor, m2
Q_h = [9.5290;7.9509;5.7226;12.7060;10.6018;9.7972;8.1296;5.8656;13.0635;10.8401;10.0653;6.7114;6.0086;5.5401;12.0155]; % Volumetric flowrate, L/h
Q = Q_h/1000; % Conversion of unit, L/h to m3/h
rho_cat = 500; % catalyst density, kg/m3
c10 = 100.*P./(R.*(T+273.15)); % first concentration of H2
X = [6.6;10.2;12.7;5.6;9.7;14.2;16.5;18;13.5;15.1;22;30.2;33.1;44.4;29.6]; % Conversion
c = c10.*(1-X./100); % last concentration of H2
V = Q/S; % linear velocity of fluid
%% paramter estimation a1 ~ a4
in = rand(1,4); %random value for initial value of a1 ~ a4
options = optimset('Display','iter','TolX', 1e-15, 'TolFun', 1e-15, 'MaxFunEvals', 4000, 'MaxIter', 4000,'Algorithm','Levenberg-Marquardt')
[in1,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqnonlin(@(in1)myfunct(in1,c,t,c10,rho_cat,P,V,R,T),in,[],[],options)
in1
end
function res = myfunct(in1,c,t,c10,rho_cat,P,V,R,T)
tspan = [0 t];
for i = 1:numel(P)
func = @(tt,y)(-(rho_cat / V(i)) * in1(1)* exp(-in1(2) / (R * (T(i)+273.15))) * ...
(y(1)^in1(3))) / (1+in1(4)*y(1));
[T,sol] = ode15s(func,tspan,c10(i));
res(i) = c(i)-sol(end,1);
end
end
11 Comments
Taeksang Yoon
on 3 Jan 2022
Walter Roberson
on 3 Jan 2022
function in1 = main
Taeksang Yoon
on 10 Jan 2022
Replace
[T,sol] = ode15s(func,tspan,c10(i));
by
[~,sol] = ode15s(func,tspan,c10(i));
to avoid conflicts with the temperature array T.
Of course, the arrays for P, T, V, c and c10 must be of the same size for the code to run properly.
If the solver does not converge is a different problem.
Taeksang Yoon
on 11 Jan 2022
Taeksang Yoon
on 14 Jan 2022
Taeksang Yoon
on 17 Jan 2022
Torsten
on 17 Jan 2022
Yes, set P_new, T_new, V_new, c_new and c10_new for the other data and call ode15s with the parameters "in1" obtained from the optimization:
in = rand(1,4); %random value for initial value of a1 ~ a4
options = optimset('Display','iter','TolX', 1e-15, 'TolFun', 1e-15, 'MaxFunEvals', 4000, 'MaxIter', 4000,'Algorithm','Levenberg-Marquardt')
[in1,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqnonlin(@(in1)myfunct(in1,c,t,c10,rho_cat,P,V,R,T),in,[],[],options)
P_new = ...;
T_new = ...;
V_new = ...;
c_new = ...;
c10_new = ...;
res = myfunct(in1,c_new,t,c10_new,rho_cat,P_new,V_new,R,T_new)
Taeksang Yoon
on 20 Jan 2022
Categories
Find more on Conversion Between Symbolic and Numeric in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




