Using Symbolic Variable in ODE45 without Separate Function and other advice
이전 댓글 표시
Hi,
So, I'm trying to evaluate a system of ODEs
I can replace dC with the reaction rate and arrive upon:

At this point, we're unable to solve the problem analytically.
First, I'd like to know how to solve this using ODE45. I have attempted this using the following code:
syms T t
% constants
Tm = 300; %K
Cao = 2; %mol/L
Cpa = 20; %cal/mol-K
Hr = -10000; %cal/mol
EaR = 2660; %K
km = 0.01725; %L/mol-min
Ta = 300; %K
UAVr = 0.1; %cal/mol-L-K
% system equations
k = km*exp(-EaR*(1/T-1/Tm))
Ca = Cao/(Cao*k*t + 1)
% ODE
dT = Hr*k*Ca^2/(2*Cao*Cpa) + UAVr/(2*Cao*Cpa)*(Ta-T)
tspan=[0 30];
% ODE solver
[t,T] = ode45(@(t,T)dT,tspan,300)
The problem is that dT is a sym variable, I understand that. I don't understand how I can turn it into something that ODE45 will recognize.
I believe I could just paste the equation output of dT, but that doesn't help the next step. It needs to be something that can take the characters from the output of dT and turn it into a function handle. I've tried multiple methods, but it seems I fundamentally don't understand the code.
The ultimate goal of this code is to determine a value of
such that 
The behavior of T is that is trends to a max and then trails off, but the location of the max changes dramatically depending on the value of
. I was planning to run a loop until this was true. I'm sure there are better ways. Any ideas?
답변 (1개)
Walter Roberson
2020년 4월 4일
편집: Walter Roberson
2020년 4월 4일
dT = matlabFunction(Hr*k*Ca^2/(2*Cao*Cpa) + UAVr/(2*Cao*Cpa)*(Ta-T), 'vars', {t, T});
and
[t,T] = ode45(dT,tspan,300);
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!