How can I solve the fsolve function inside an ode15s function?

조회 수: 1 (최근 30일)
Marcela Ruiz de Chávez
Marcela Ruiz de Chávez 2015년 5월 17일
댓글: Torsten 2015년 5월 18일
Hi,
I need to solve an fsolve function inside an ode15s function. However, the dependent variable in the differential equation is contained in the system of linear equations. How can I solve this? This is what I have but it says there is a problem:
%file1.m
clc; clear all; close all; format compact;
global A_T Fao P_tot DELTAHr E A R To Tf
%Datos
A_T = pi*1^2;%m
Fao = (66000*1000)/92.14; %kmol/año
P_tot = 50; %bar
DELTAHr = 49974; %KJ/Kmol
%Cálculo de k
E = 148114;
A = 5.73E6;
R = 8.3144;
To = 600+273;
Tf = 635+273;
Zo = 0;
Zf = 100;
yo = [To, 0];
[F fval flag] = fsolve('fun',[3 10])
[T, xa] = ode15s('odefun', [Zo Zf], yo)
%file2.m
function F = fun(var)
global A_T Fao P_tot DELTAHr E A R To Tf FA FR CPA CPB CPR CPS CQP
FB = var(1)
FS = var(2)
Q = var(3)
F(1) =-FB + Fao*(5-x_a) + 0.9*Q ;
F(2) =-FS + Fao*(5/9 + x_a) + 0.1*Q;
F(3) = -Q +(FA*CPA*(T-To)+ FB*CPB*(T-To)+ FR*CPR*(T-To)+ FS*CPS*(T-To))/(CQP*(To-298));
end
%file3.m
function dvdz = odefun(T, x_a)
global A_T Fao P_tot DELTAHr E A R To CPA CPB CPR CPS CQP FA FR
K = A*exp(-E/R*T);
CPA = 0.29 + 47.052E3*T - 15.716E6*T^2;
CPB = 3.249 + 0.422E3*T + 0.083E-5*T^-2;
CPR = -.206 + 39.064E3*T - 13.301E6*T^2;
CPS = 1.702 + 9.081E3*T - 2.164E6*T^2;
CQP = CPB*0.9 + CPS*0.1;
FA = Fao*(1-x_a);
FR = Fao*x_a;
var0 = [100 100 100];
[var] = fsolve('fun', var0);
var(1) = FB ;
var(2) = FS ;
var(3) = Q;
dvdz(1) = (A_T/Fao)*K*(P_tot/R*T)^1.5*(Fao*(1-x_a))*(((Fao*(5-x_a) + 0.9*Q))^0.5/(6.55*Fao + Q)^1.5);
dvdz(2) = (Fao*DELTAHr/(FA*CPA*(T-To)+ FB*CPB*(T-To)+ FR*CPR*(T-To)+ FS*CPS*(T-To)))*dvdz(1);
dvdz = dvdz'
end
Thank you!
  댓글 수: 1
Torsten
Torsten 2015년 5월 18일
From your code above, I don't understand which system you are trying to solve.
If it helps: Usually, there is no Need to solve algebraic equations separately. The ODE solvers are suited to solve a mixture of algebraic and differential equations. Take a look at the differential-algebraic example under
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by