From: Fredric on
Hi all,

trying to solve a system of non-linear equations with fsolve but without success. These are my files

--------------
%main

global Ab thick Dp ac W_n P porosity L R T_0 F_A0 F_B0 F_C0 F_D Db Dr T_o

%all the global variables are problem constants

x0=[1e-2 1e-4 .2 400 400 100 1]; % [k_c D_AB X T_r T_w Q m_steam]

[x,fval] = fsolve(@tankreactor,x0)

---------------
function y = tankreactor(x)
global Ab thick Dp ac W P porosity L R T_0 F_A0 F_B0 F_C0 F_D Db Dr T_o

M_D = .018;
mu_v = 1.4055e-05;
rho_v = 2.6658;
rho_l = 915.48;
lambda_v = 0.03187;
k_steel = 17;
DeltaH_vap = 2257;
DeltaH_reac = -102.95;
v_0 = (F_A0+ F_B0+ F_C0+ F_D)*R*T_0/(P*Ab);


y = [F_A0 - F_A0*(1-x(3))*(1 + x(1)*ac*W/(F_A0*(1-x(3))+F_B0+F_C0+F_D)*P/(R*x(4)));

-(Cp('A',x(4))*F_A0*(1-x(3))+Cp('B',x(4))*(F_B0-F_A0*x(3))+Cp('C',x(4))*(F_C0+F_A0*x(3))+Cp('D',x(4))*F_D)*(x(4)-T_0)*.001 ...
+ DeltaH_reac*x(1)*ac*W*F_A0*(1-x(3))/(F_A0*(1-x(3))+F_B0+F_C0+F_D)*(P/(R*x(4))) + x(6);

x(6) - (21*thermal_cond(x(4)) + 0.23*(v_0*Dp*P/(R*x(4))*(Cp('A',x(4))*F_A0*(1-x(3))+Cp('B',x(4))*(F_B0-F_A0*x(3))+ ...
Cp('C',x(4))*(F_C0+F_A0*x(3))+Cp('D',x(4))*F_D)/(F_A0*(1-x(3))+F_B0+F_C0+F_D)))*.001*(x(5)-x(4))*(Db/2);

x(6) - (1/((21*thermal_cond(x(4)) + 0.23*(v_0 * Dp * P/(R*x(4)) * (Cp('A',x(4))*F_A0*(1-x(3))+Cp('B',x(4))*(F_B0-F_A0*x(3))+ ...
Cp('C',x(4))*(F_C0+F_A0*x(3))+Cp('D',x(4))*F_D)/(F_A0*(1-x(3))+F_B0+F_C0+F_D)))*2.8*(v_0 * Dp * P/(R*x(4)) * ...
((Cp('A',x(4))*F_A0*(1-x(3))+Cp('B',x(4))*(F_B0-F_A0*x(3))+Cp('C',x(4))*(F_C0+F_A0*x(3))+Cp('D',x(4))*F_D)/ ...
(F_A0*(1-x(3))+F_B0+F_C0+F_D))/thermal_cond(x(4)))^(-.25)/Dp) + (thick/k_steel) + 1/(.002*(4*x(7)/(pi*Dr*mu_v))^.6* ...
(mu_v/(rho_v*9.81*(rho_l-rho_v)*lambda_v^3))^(-1/3)))^(-1)*.001*(T_o-x(5))*pi*L*(Db+thick/2);

x(6) - (DeltaH_vap*x(7));

(0.765/((P*M_D*v_0*Dp/(R*x(4)*viscosity(x(4))))^.82) + 0.365/(P*M_D*v_0*Dp/((R*x(4)*viscosity(x(4))))^.386))/porosity - ...
(x(1)*Dp/x(2))/((viscosity(x(4))*R*x(4)/(P*M_D*x(2)))^(1/3) * P*M_D*v_0*Dp/(R*x(4)*viscosity(x(4))));

x(1)*Dp/x(2) - (2 + 0.6*((P*M_D*v_0*Dp/(R*x(4)*viscosity(x(4))))^.5)*((viscosity(x(4))*R*x(4)/(P*M_D*x(2)))^(1/3)))];

------------------

Cp.m, thermal_conductivity.m and viscosity.m are support files.

I have seven unknown variables and seven equations but receive the following error message when trying to solve the system


------------------
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using
Levenberg-Marquardt algorithm instead.
> In fsolve at 324
In model_main at 60

No solution found.

fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
default value of the function tolerance.
------------------

I have tried relaxing the tolerances and changing the initial points without success.

Thanks for any advice on how to proceed with this problem!

// Fredric
From: John D'Errico on
"Fredric " <fredricb(a)student.chalmers.se> wrote in message <i3ua49$s8t$1(a)fred.mathworks.com>...
> Hi all,
>
> trying to solve a system of non-linear equations with fsolve but without success. These are my files
>

Why do you know that a solution must exist?

Not every problem has a solution.

John
From: Fredric on
"John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i3ucua$7rd$1(a)fred.mathworks.com>...
> "Fredric " <fredricb(a)student.chalmers.se> wrote in message <i3ua49$s8t$1(a)fred.mathworks.com>...
> > Hi all,
> >
> > trying to solve a system of non-linear equations with fsolve but without success. These are my files
> >
>
> Why do you know that a solution must exist?
>
> Not every problem has a solution.
>
> John


The problem describes transport of heat and mass through a chemical reactor and thus I am quite certain that there must be a solution (i.e. that what goes into the reactor comes out).

//
From: Gene on
"Fredric " <fredricb(a)student.chalmers.se> wrote in message <i3ud9g$187$1(a)fred.mathworks.com>...
> "John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i3ucua$7rd$1(a)fred.mathworks.com>...
> > "Fredric " <fredricb(a)student.chalmers.se> wrote in message <i3ua49$s8t$1(a)fred.mathworks.com>...
> > > Hi all,
> > >
> > > trying to solve a system of non-linear equations with fsolve but without success. These are my files
> > >
> >
> > Why do you know that a solution must exist?
> >
> > Not every problem has a solution.
> >
> > John
>
>
> The problem describes transport of heat and mass through a chemical reactor and thus I am quite certain that there must be a solution (i.e. that what goes into the reactor comes out).
>
> //

Hi Fredric:

Do you know that your 'tankreactor' function returns a real, 7 dimensional value ? The Matlab message implies that it doesn't think so. Without knowing what the
Cp.m, thermal_conductivity.m and viscosity.m support files return it's hard to deduce this from your code. One of the 'lines' delimited by ';' could evaluate to a n by 1 vector.

Also, as noted by John D's existence of a solution (more generally well-posedness) of the mathematical problem does not follow from the fact that the physical problem has a solution.
From: carlos lopez on
"Fredric " <fredricb(a)student.chalmers.se> wrote in message <i3ua49$s8t$1(a)fred.mathworks.com>...
> Hi all,
>
> trying to solve a system of non-linear equations with fsolve but without success. These are my files
....
> Thanks for any advice on how to proceed with this problem!
>
> // Fredric
Hello Fredric:
In addition to the other answers, I wonder if you have verified your code with a "known" solution, i.e. changing the inner constants and parameters to solve the problem with one particular vector x.
Your code just evaluates a penalty function given the unknown vector, so it should have just one universal solution. I guess it is not universal, but it looks like...
I can also guess that by varying one or more of the parameter transmitted through the global statements you indeed find a different solution x.
So, if you know that x0 is the exact solution with parameters P0 (whichever they are or mean) then you can try to find the solution with parameters P (different from P0) by solving intermediate problems with intermediate parameters value. Search for "continuation methods".
Regards
Carlos