Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Finding no solution with fsolve

Subject: Finding no solution with fsolve

From: Fredric

Date: 11 Aug, 2010 13:55:21

Message: 1 of 7

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

Subject: Finding no solution with fsolve

From: John D'Errico

Date: 11 Aug, 2010 14:43:22

Message: 2 of 7

"Fredric " <fredricb@student.chalmers.se> wrote in message <i3ua49$s8t$1@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

Subject: Finding no solution with fsolve

From: Fredric

Date: 11 Aug, 2010 14:49:20

Message: 3 of 7

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <i3ucua$7rd$1@fred.mathworks.com>...
> "Fredric " <fredricb@student.chalmers.se> wrote in message <i3ua49$s8t$1@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).

//

Subject: Finding no solution with fsolve

From: Gene

Date: 11 Aug, 2010 15:37:20

Message: 4 of 7

"Fredric " <fredricb@student.chalmers.se> wrote in message <i3ud9g$187$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <i3ucua$7rd$1@fred.mathworks.com>...
> > "Fredric " <fredricb@student.chalmers.se> wrote in message <i3ua49$s8t$1@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.

Subject: Finding no solution with fsolve

From: carlos lopez

Date: 11 Aug, 2010 16:01:21

Message: 5 of 7

"Fredric " <fredricb@student.chalmers.se> wrote in message <i3ua49$s8t$1@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

Subject: Finding no solution with fsolve

From: Fredric

Date: 12 Aug, 2010 06:42:23

Message: 6 of 7

"Gene " <ecliff@vt.edu> wrote in message <i3ug3g$7so$1@fred.mathworks.com>...
> "Fredric " <fredricb@student.chalmers.se> wrote in message <i3ud9g$187$1@fred.mathworks.com>...
> > "John D'Errico" <woodchips@rochester.rr.com> wrote in message <i3ucua$7rd$1@fred.mathworks.com>...
> > > "Fredric " <fredricb@student.chalmers.se> wrote in message <i3ua49$s8t$1@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.

Hi Gene,
all the support files return scalar values, I do however not see which line you mean could evaluate to a n-by-1-vector depending on these support files - cold you perhaps clarify that? That might explain why the matlab message states that it is a non suare system, could it not?

Thanks for the help!

// Fredric

Subject: Finding no solution with fsolve

From: Gene

Date: 12 Aug, 2010 13:14:05

Message: 7 of 7

> > 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.
>
> Hi Gene,
> all the support files return scalar values, I do however not see which line you mean could evaluate to a n-by-1-vector depending on these support files - cold you perhaps clarify that? That might explain why the matlab message states that it is a non suare system, could it not?
>
> Thanks for the help!
>
> // Fredric

Fredric:
Sorry if I caused any confusion - I do not know that any line 'does evaluate' to a n by 1 vector, only that Matlab would be perfectly happy to evaluate it, since such 'stacking' of column vectors is permissible.

I suggest that you simply try to evaluate
y = testreactor(x0)
and see if y is a 7 component 1D array. More generally, find out why 'fsolve' complains about a non-square array.

Good Luck

gene

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us