Problem with system of non linear equation

1 Ansicht (letzte 30 Tage)
Giuseppe
Giuseppe am 25 Okt. 2014
Beantwortet: Giuseppe am 26 Okt. 2014
Hi Guys, i'm Giuseppe and i would have some advice in order to solve the problem of my code.
i need to create a function that solve this stupid equation system:
where all the terms are known, except x, y and z that represent the solutions that i'm trying to calculate.
the function should be able to accept all well-known terms, and give out x, y, z.
i tried to use fsolve, but it doesn't work..
can someone help me? thanks in Advance!
greetings, Giuseppe
  2 Kommentare
Zoltán Csáti
Zoltán Csáti am 25 Okt. 2014
What do you mean under fsolve does not work? Doesn't it give you the solution or you can not use it?
Giuseppe
Giuseppe am 26 Okt. 2014
Bearbeitet: Giuseppe am 26 Okt. 2014
Basically, i have two problems:
1) Using fsolve, i'm not able to give all the constant terms as input parameter! I tried to read about it on the Help page: there is a specific topic - how to pass extra parameters, but something should be wrong. Matlab say: "Error using ==> fminunc at 301 User supplied objective function must return a scalar value." (Sincerely, i'm not sure if that problems is related to "fisical code" that i implemented or is just a syntax error..)
2) So, firstly, i decide to try introducing all the constants in the body of function created. here, when i tried to solve it, it seemed to work but, when i try to change some values of constants, i obtain messages like: or Equation Solved (and i think it's ok) or Equation Solved, fvsolve stalled; or Solver stopped prematurely -fsolve stopped because it exceeded the function evaluation limit, options.MaxFunEvals = 500 (the selected value).
this is the code that i implemented :
function [funz] =solver(x) %Equilibrium Calculation Uf=0.65; % T_cell=600; %°C T_c=T_cell+273.15; %[K]
[K_ref K_wgs]=C_equilibrio(T_c); %NOTE: this is an external function..
%Mass flow - Fuel da DESIGN POINT CONFIG.xls Gfuel=100; %[mol/s] Biogas Flow rate
%Composizione % gas iniziale CH4=0.60; % H2=0; % CO2=0.4; % CO=0; % H2O=0; %
%Composizione molare gas iniziale m_CH4=CH4*Gfuel; %[mol/s] m_H2=H2*Gfuel; %[mol/s] m_H2Of=H2O*Gfuel; %[mol/s] m_CO2=CO2*Gfuel; %[mol/s] m_CO=CO*Gfuel; %[mol/s]
%SC - Steam to Carbon ratio SC=2.5; m_H2O=SC*m_CH4; %[mol/s]
n_tot=m_CH4+m_H2+m_H2O+m_CO2+m_CO; %[mol/s]
p_cell=1; %[bar];
funz=[K_ref-(p_cell^2)*((((m_CO+x(1)-x(2))/(n_tot+2*x(1)))*((m_H2+3*x(1)+x(2)-x(3))/(n_tot+2*x(1)))^3)/(((m_CH4-x(1))/(n_tot+2*x(1)))*((m_H2O-x(1)-x(2)+x(3))/(n_tot+2*x(1)))));
K_wgs-(((m_H2+3*x(1)+x(2)-x(3))/(n_tot+2*x(1)))*((m_CO2+x(2))/(n_tot+2*x(1))))/(((m_CO+x(1)-x(2))/(n_tot+2*x(1)))*((m_H2O-x(1)-x(2)+x(3))/(n_tot+2*x(1))));
x(3)-Uf*(3*x(1)+x(2)+m_H2)];
If you need other informations, please ask me and i'll answer back as soon is possilbe!"

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Giuseppe
Giuseppe am 26 Okt. 2014
Basically, i have two problems:
1) Using fsolve, i'm not able to give all the constant terms as input parameter! I tried to read about it on the Help page: there is a specific topic - how to pass extra parameters, but something should be wrong. Matlab say: "Error using ==> fminunc at 301 User supplied objective function must return a scalar value." (Sincerely, i'm not sure if that problems is related to "fisical code" that i implemented or is just a syntax error..)
2) So, firstly, i decide to try introducing all the constants in the body of function created. here, when i tried to solve it, it seemed to work but, when i try to change some values of constants, i obtain messages like: or Equation Solved (and i think it's ok) or Equation Solved, fvsolve stalled; or Solver stopped prematurely -fsolve stopped because it exceeded the function evaluation limit, options.MaxFunEvals = 500 (the selected value).
this is the code that i implemented :
function [funz] =solver(x) %Equilibrium Calculation Uf=0.65; % T_cell=600; %°C T_c=T_cell+273.15; %[K]
[K_ref K_wgs]=C_equilibrio(T_c); %NOTE: this is an external function..
%Mass flow - Fuel da DESIGN POINT CONFIG.xls Gfuel=100; %[mol/s] Biogas Flow rate
%Composizione % gas iniziale CH4=0.60; % H2=0; % CO2=0.4; % CO=0; % H2O=0; %
%Composizione molare gas iniziale m_CH4=CH4*Gfuel; %[mol/s] m_H2=H2*Gfuel; %[mol/s] m_H2Of=H2O*Gfuel; %[mol/s] m_CO2=CO2*Gfuel; %[mol/s] m_CO=CO*Gfuel; %[mol/s]
%SC - Steam to Carbon ratio SC=2.5; m_H2O=SC*m_CH4; %[mol/s]
n_tot=m_CH4+m_H2+m_H2O+m_CO2+m_CO; %[mol/s]
p_cell=1; %[bar];
funz=[K_ref-(p_cell^2)*((((m_CO+x(1)-x(2))/(n_tot+2*x(1)))*((m_H2+3*x(1)+x(2)-x(3))/(n_tot+2*x(1)))^3)/(((m_CH4-x(1))/(n_tot+2*x(1)))*((m_H2O-x(1)-x(2)+x(3))/(n_tot+2*x(1)))));
K_wgs-(((m_H2+3*x(1)+x(2)-x(3))/(n_tot+2*x(1)))*((m_CO2+x(2))/(n_tot+2*x(1))))/(((m_CO+x(1)-x(2))/(n_tot+2*x(1)))*((m_H2O-x(1)-x(2)+x(3))/(n_tot+2*x(1))));
x(3)-Uf*(3*x(1)+x(2)+m_H2)];

Kategorien

Mehr zu General Applications finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by