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:
Solving non-linear simultaneous equation with "Ln" in equations

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Zaki

Date: 18 May, 2012 14:19:13

Message: 1 of 12

Hi everybody,

I'm quite new in Matlab. I'm currently working on solving 15 equations and 15 unknowns. And I realize that I need some serious assistance.

Unknowns are: Y1 to Y15. G1 to G11 are just numbers that I will feed into the equations.

Equations 1 to 11 has in logarithmic of the unknowns, to be specific it is
"Ln Y1", "Ln Y2", "Ln Y3", ........ "Ln Y11", and not Log(10). All of these Y1, Y2, Y3, .... Y11 are my unknowns.

The equations are as follows:

Eq.1) G1 + LnY1 + 3Y12 + 8Y13 + 3Y14 = 0
Eq.2) G2 + LnY2 + 2Y13 + Y14 = 0
Eq.3) G3 + LnY3 + 2Y12 + 4Y13 = 0
Eq.4) G4 + LnY4 + 2Y12 + 6Y13 = 0
Eq.5) G5 + LnY5 + 3Y12 + 6Y13 = 0
Eq.6) G6 + LnY6 + 3Y12 + 813 = 0
Eq.7) G7 + LnY7 + Y12 + 4Y13 = 0
Eq.8) LnY8 + 2Y13 = 0
Eq.9) G9 + LnY9 + Y12 + 2Y14 = 0
Eq.10) G10 + LnY10 + Y12 + Y14 = 0
Eq.11) G11 + LnY11 + Y12 = 0
Eq.12) 3Y1 + 2Y3 + 2Y4 + 3Y5 + 3Y6 + Y7 + Y9 + Y10 + Y11 - 4 = 0
Eq.13) 8Y1 + 2Y2 + 4Y3 + 6Y4 + 6Y5 + 8Y6 +4Y7 +2Y8 - 8 = 0
Eq.14) 3Y1 + Y2 + Y9 + Y10 + 2Y11 - 9 = 0
Eq.15) Y1 + Y2 + Y3 + Y4 + Y5 + Y6 + Y7 + Y8 + Y9 + Y10 + Y11 - Y15 = 0

What should my approach be?

I appreciate any assistance from all of you.

Thanks in advance.

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Alan Weiss

Date: 18 May, 2012 15:22:12

Message: 2 of 12

On 5/18/2012 10:19 AM, Zaki wrote:
> Hi everybody,
>
> I'm quite new in Matlab. I'm currently working on solving 15 equations
> and 15 unknowns. And I realize that I need some serious assistance.
>
> Unknowns are: Y1 to Y15. G1 to G11 are just numbers that I will feed
> into the equations.
> Equations 1 to 11 has in logarithmic of the unknowns, to be specific it
> is "Ln Y1", "Ln Y2", "Ln Y3", ........ "Ln Y11", and not Log(10). All of
> these Y1, Y2, Y3, .... Y11 are my unknowns.
> The equations are as follows:
>
> Eq.1) G1 + LnY1 + 3Y12 + 8Y13 + 3Y14 = 0
> Eq.2) G2 + LnY2 + 2Y13 + Y14 = 0
> Eq.3) G3 + LnY3 + 2Y12 + 4Y13 = 0
> Eq.4) G4 + LnY4 + 2Y12 + 6Y13 = 0
> Eq.5) G5 + LnY5 + 3Y12 + 6Y13 = 0
> Eq.6) G6 + LnY6 + 3Y12 + 813 = 0
> Eq.7) G7 + LnY7 + Y12 + 4Y13 = 0
> Eq.8) LnY8 + 2Y13 = 0
> Eq.9) G9 + LnY9 + Y12 + 2Y14 = 0
> Eq.10) G10 + LnY10 + Y12 + Y14 = 0
> Eq.11) G11 + LnY11 + Y12 = 0
> Eq.12) 3Y1 + 2Y3 + 2Y4 + 3Y5 + 3Y6 + Y7 + Y9 + Y10 + Y11 - 4 = 0
> Eq.13) 8Y1 + 2Y2 + 4Y3 + 6Y4 + 6Y5 + 8Y6 +4Y7 +2Y8 - 8 = 0
> Eq.14) 3Y1 + Y2 + Y9 + Y10 + 2Y11 - 9 = 0
> Eq.15) Y1 + Y2 + Y3 + Y4 + Y5 + Y6 + Y7 + Y8 + Y9 + Y10 + Y11 - Y15 = 0
>
> What should my approach be?
> I appreciate any assistance from all of you.
>
> Thanks in advance.

It looks to me as if the first 11 equations give Y1 through Y11 in terms
of Y12, Y13, and Y14. Similarly for equation 15.

So I suggest you consider equation 12 through 14 as nonlinear equations
for Y12, Y13, and Y14. Solve for those three variables using fsolve (I
assume you have an Optimization Toolbox license). Then find Y1-Y11 and Y15.

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Zaki

Date: 21 May, 2012 10:31:08

Message: 3 of 12

Thanks Alan for your kind feedback,

Yep, this situation is like a combination between nonlinear and linear equations. However, the situation requires every unknown to be solve at one point simultaneously. Another problem is, if I consider equations 12 to 14 as a linear equation, unknowns Y12, Y13 and Y14 are not present in that equations.

Is it OK to use fsolve in this situation (linear and nonlinear)?

Thanks


"Zaki " <zaki.yz@gmail.com> wrote in message <jp5lp1$m4d$1@newscl01ah.mathworks.com>...
> Hi everybody,
>
> I'm quite new in Matlab. I'm currently working on solving 15 equations and 15 unknowns. And I realize that I need some serious assistance.
>
> Unknowns are: Y1 to Y15. G1 to G11 are just numbers that I will feed into the equations.
>
> Equations 1 to 11 has in logarithmic of the unknowns, to be specific it is
> "Ln Y1", "Ln Y2", "Ln Y3", ........ "Ln Y11", and not Log(10). All of these Y1, Y2, Y3, .... Y11 are my unknowns.
>
> The equations are as follows:
>
> Eq.1) G1 + LnY1 + 3Y12 + 8Y13 + 3Y14 = 0
> Eq.2) G2 + LnY2 + 2Y13 + Y14 = 0
> Eq.3) G3 + LnY3 + 2Y12 + 4Y13 = 0
> Eq.4) G4 + LnY4 + 2Y12 + 6Y13 = 0
> Eq.5) G5 + LnY5 + 3Y12 + 6Y13 = 0
> Eq.6) G6 + LnY6 + 3Y12 + 813 = 0
> Eq.7) G7 + LnY7 + Y12 + 4Y13 = 0
> Eq.8) LnY8 + 2Y13 = 0
> Eq.9) G9 + LnY9 + Y12 + 2Y14 = 0
> Eq.10) G10 + LnY10 + Y12 + Y14 = 0
> Eq.11) G11 + LnY11 + Y12 = 0
> Eq.12) 3Y1 + 2Y3 + 2Y4 + 3Y5 + 3Y6 + Y7 + Y9 + Y10 + Y11 - 4 = 0
> Eq.13) 8Y1 + 2Y2 + 4Y3 + 6Y4 + 6Y5 + 8Y6 +4Y7 +2Y8 - 8 = 0
> Eq.14) 3Y1 + Y2 + Y9 + Y10 + 2Y11 - 9 = 0
> Eq.15) Y1 + Y2 + Y3 + Y4 + Y5 + Y6 + Y7 + Y8 + Y9 + Y10 + Y11 - Y15 = 0
>
> What should my approach be?
>
> I appreciate any assistance from all of you.
>
> Thanks in advance.

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Torsten

Date: 21 May, 2012 10:53:35

Message: 4 of 12

On 21 Mai, 12:31, "Zaki " <zaki...@gmail.com> wrote:
> Thanks Alan for your kind feedback,
>
> Yep, this situation is like a combination between nonlinear and linear equations. However, the situation requires every unknown to be solve at one point simultaneously. Another problem is, if I consider equations 12 to 14 as a linear equation, unknowns Y12, Y13 and Y14 are not present in that equations.
>
> Is it OK to use fsolve in this situation (linear and nonlinear)?
>
> Thanks
>
>
>
> "Zaki " <zaki...@gmail.com> wrote in message <jp5lp1$m4...@newscl01ah.mathworks.com>...
> > Hi everybody,
>
> > I'm quite new in Matlab. I'm currently working on solving 15 equations and 15 unknowns. And I realize that I need some serious assistance.
>
> > Unknowns are: Y1 to Y15. G1 to G11 are just numbers that I will feed into the equations.
>
> > Equations 1 to 11 has in logarithmic of the unknowns, to be specific it is
> > "Ln Y1", "Ln Y2", "Ln Y3", ........ "Ln Y11", and not Log(10). All of these Y1, Y2, Y3, .... Y11 are my unknowns.
>
> > The equations are as follows:
>
> > Eq.1) G1 + LnY1 + 3Y12 + 8Y13 + 3Y14 = 0
> > Eq.2) G2 + LnY2 + 2Y13 + Y14 = 0
> > Eq.3) G3 + LnY3 + 2Y12 + 4Y13 = 0
> > Eq.4) G4 + LnY4 + 2Y12 + 6Y13 = 0
> > Eq.5) G5 + LnY5 + 3Y12 + 6Y13 = 0
> > Eq.6) G6 + LnY6 + 3Y12 + 813 = 0
> > Eq.7) G7 + LnY7 + Y12 + 4Y13 = 0
> > Eq.8) LnY8 + 2Y13 = 0
> > Eq.9) G9 + LnY9 + Y12 + 2Y14 = 0
> > Eq.10) G10 + LnY10 + Y12 + Y14 = 0
> > Eq.11) G11 + LnY11 + Y12 = 0
> > Eq.12) 3Y1 + 2Y3 + 2Y4 + 3Y5 + 3Y6 + Y7 + Y9 + Y10 + Y11 - 4 = 0
> > Eq.13) 8Y1 + 2Y2 + 4Y3 + 6Y4 + 6Y5 + 8Y6 +4Y7 +2Y8 - 8 = 0
> > Eq.14) 3Y1 + Y2 + Y9 + Y10 + 2Y11 - 9 = 0
> > Eq.15) Y1 + Y2 + Y3 + Y4 + Y5 + Y6 + Y7 + Y8 + Y9 + Y10 + Y11 - Y15 = 0
>
> > What should my approach be?
>
> > I appreciate any assistance from all of you.
>
> > Thanks in advance.- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

What Alan meant is the following:

Solve Eq1) - Eq11) manually for Y1,...,Y11:
Eq1) gives Y1=exp(-G1-(3Y12 + 8Y13 + 3Y14))
Eq2) gives Y2=exp(-G2-(2Y13 + Y14))
Eq3) gives Y3=exp(-G3-( 2Y12 + 4Y13))
...
Eq11) gives Y11=exp(-G11-Y12)

Insert Y1,...,Y11 in Eq12)-Eq14) manually:
3*exp(-G1-(3Y12 + 8Y13 + 3Y14)) +2*exp(-G3-( 2Y12 + 4Y13))+...+exp(-
G11-Y12)-4=0
8*exp(-G1-(3Y12 + 8Y13 + 3Y14)) +2*exp(-G2-(2Y13 + Y14))+4*exp(-G3-
( 2Y12 + 4Y13))+...-8=0
3*exp(-G1-(3Y12 + 8Y13 + 3Y14))+exp(-G2-(2Y13 + Y14))+...+2*exp(-G11-
Y12)-9 = 0

Solve these _3_ equations in Y12, Y13 and Y14 using fsolve.

With the result, deduce Y1,Y2,Y3,...,Y11,Y15 by inserting Y12, Y13 and
Y14 :
Y1=exp(-G1-(3Y12 + 8Y13 + 3Y14))
Y2=exp(-G2-(2Y13 + Y14))
Y3=exp(-G3-( 2Y12 + 4Y13))
...
Y11=exp(-G11-Y12)
Y15=Y1 + Y2 + Y3 + Y4 + Y5 + Y6 + Y7 + Y8 + Y9 + Y10 + Y11

Best wishes
Torsten.

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Roger Stafford

Date: 21 May, 2012 19:22:06

Message: 5 of 12

"Zaki " <zaki.yz@gmail.com> wrote in message <jpd5hc$kad$1@newscl01ah.mathworks.com>...
> However, the situation requires every unknown to be solve at one point simultaneously. Another problem is, if I consider equations 12 to 14 as a linear equation, unknowns Y12, Y13 and Y14 are not present in that equations.
>
> Is it OK to use fsolve in this situation (linear and nonlinear)?
- - - - - - - - -
  Zaki, Alan Weiss has given you excellent advice which you should not dismiss so easily. As Torsten has pointed out, Alan's method does allow every unknown to be solved in a manner that gives a simultaneous solution, even though you present 'fsolve' with only three unknowns. The other twelve corresponding unknown values can then be readily and uniquely determined.

  In the documentation for 'fsolve', Mathworks promises only this:

"fsolve finds a root (zero) of a system of nonlinear equations. x = fsolve(fun,x0) starts at x0 and tries to solve the equations described in fun."

Fsolve starts at x0 and tries to find A root, not all roots! If your aim is to locate all possible roots, you are faced with the serious problem of using a sufficiently large variety of initial x0 estimates as to be able to eventually locate all the roots. This is immeasurably more difficult with fifteen unknowns that it would be with three, and that is one very powerful reason for reducing the number of unknowns presented to 'fsolve'.

  By all means take Alan's advice. You will have enough difficulty finding all roots even with only three unknowns.

  In answer to the question you asked, "Is it OK to use fsolve in this situation" (using all fifteen unknowns,) the answer is yes, but it may take you a long time to deal properly with the search for all possible roots with a fifteen-dimensional x0 for initial estimates. Also it will very likely require 'fsolve' a lot longer in its search.

Roger Stafford

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Zaki

Date: 22 May, 2012 08:49:07

Message: 6 of 12

Dear Alan, Torsten and Roger,

Thanks for your advice / recommendation. Since yesterday, I'm trying and trying to solve this using your recommendation.

I'll surely let you know the progress / updates since this problem is so important for me to solve.

Thanks very much.



"Roger Stafford" wrote in message <jpe4ku$cu7$1@newscl01ah.mathworks.com>...
> "Zaki " <zaki.yz@gmail.com> wrote in message <jpd5hc$kad$1@newscl01ah.mathworks.com>...
> > However, the situation requires every unknown to be solve at one point simultaneously. Another problem is, if I consider equations 12 to 14 as a linear equation, unknowns Y12, Y13 and Y14 are not present in that equations.
> >
> > Is it OK to use fsolve in this situation (linear and nonlinear)?
> - - - - - - - - -
> Zaki, Alan Weiss has given you excellent advice which you should not dismiss so easily. As Torsten has pointed out, Alan's method does allow every unknown to be solved in a manner that gives a simultaneous solution, even though you present 'fsolve' with only three unknowns. The other twelve corresponding unknown values can then be readily and uniquely determined.
>
> In the documentation for 'fsolve', Mathworks promises only this:
>
> "fsolve finds a root (zero) of a system of nonlinear equations. x = fsolve(fun,x0) starts at x0 and tries to solve the equations described in fun."
>
> Fsolve starts at x0 and tries to find A root, not all roots! If your aim is to locate all possible roots, you are faced with the serious problem of using a sufficiently large variety of initial x0 estimates as to be able to eventually locate all the roots. This is immeasurably more difficult with fifteen unknowns that it would be with three, and that is one very powerful reason for reducing the number of unknowns presented to 'fsolve'.
>
> By all means take Alan's advice. You will have enough difficulty finding all roots even with only three unknowns.
>
> In answer to the question you asked, "Is it OK to use fsolve in this situation" (using all fifteen unknowns,) the answer is yes, but it may take you a long time to deal properly with the search for all possible roots with a fifteen-dimensional x0 for initial estimates. Also it will very likely require 'fsolve' a lot longer in its search.
>
> Roger Stafford

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Zaki

Date: 22 May, 2012 10:57:07

Message: 7 of 12

Dear Alan, Torsten and Roger, and others,

I've tried to solve the problem using the recommended method. So far, I have put the unknowns of Y12, Y13 & Y14 in terms of equation 1 to 11.

Following is the draft details. Later below is the code.

function GTO1

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Solve 15 Equations & 15 unknowns %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

G1=-340.02
G2=-219.98
G3=78.04767
G4=9.674889
G5=94.05569
G6=40.71902
G7=-32.28801
G8=-2.892587
G9=-399.21
G10=-164.6
G11=626.986

G1 + LnY1 + 3Y12 + 8Y13 + 3Y14 = 0 %Eq1
G2 + LnY2 + 2Y13 + Y14 = 0 %Eq2
G3 + LnY3 + 2Y12 + 4Y13 = 0 %Eq3
G4 + LnY4 + 2Y12 + 6Y13 = 0 %Eq4
G5 + LnY5 + 3Y12 + 6Y13 = 0 %Eq5
G6 + LnY6 + 3Y12 + 813 = 0 %Eq6
G7 + LnY7 + Y12 + 4Y13 = 0 %Eq7
LnY8 + 2Y13 = 0 %Eq8
G9 + LnY9 + Y12 + 2Y14 = 0 %Eq9
G10 + LnY10 + Y12 + Y14 = 0 %Eq10
G11 + LnY11 + Y12 = 0 %Eq11
3Y1 + 2Y3 + 2Y4 + 3Y5 + 3Y6 + Y7 + Y9 + Y10 + Y11 - 4 = 0 %Eq12
8Y1 + 2Y2 + 4Y3 + 6Y4 + 6Y5 + 8Y6 +4Y7 +2Y8 - 8 = 0 %Eq13
3Y1 + Y2 + Y9 + Y10 + 2Y11 - 9 = 0 %Eq14
Y1 + Y2 + Y3 + Y4 + Y5 + Y6 + Y7 + Y8 + Y9 + Y10 + Y11 - Y15 = 0 %Eq15


% Solve Equation 1 to 11 in terms of Y12, Y13, Y14


Y1=exp(-G1-(3Y12+8Y13+3Y14))
Y2=exp(-G2-(2Y13+Y14))
Y3=exp(-G3-(2Y12+4Y13))
Y4=exp(-G4-(2Y12+6Y13))
Y5=exp(-G5-(3Y12 + 6Y13))
Y6=exp(-G6-(3Y12 + 813))
Y7=exp(-G7-(Y12 + 4Y13))
Y8=exp(-G8-(2Y13))
Y9=exp(-G9-(Y12 + 2Y14))
Y10=exp(-G10-(Y12 + Y14))
Y11=exp(-G11-(Y12))

% Insert Y1 to Y11 into Equation 12 to 14.
% Equation 12
3*exp(-G1-(3Y12+8Y13+3Y14))+2*exp(-G3-(2Y12+4Y13))+2*exp(-G4-(2Y12+6Y13))+3*exp(-G5-(3Y12+6Y13))+3*exp(-G6-(3Y12+813))+exp(-G7-(Y12+4Y13))+exp(-G9-(Y12+2Y14))+exp(-G10-(Y12 + Y14))+exp(-G11-(Y12))-4=0

% Equation 13
8*exp(-G1-(3Y12+8Y13+3Y14))+2*exp(-G2-(2Y13+Y14))+4*exp(-G3-(2Y12+4Y13))+6*exp(-G4-(2Y12+6Y13))+6*exp(-G5-(3Y12 + 6Y13))+8*exp(-G6-(3Y12 + 813))+4*exp(-G7-(Y12 + 4Y13))+2*exp(-G8-(2Y13))-8=0

% Equation 14
3*exp(-G1-(3Y12+8Y13+3Y14))+exp(-G2-(2Y13+Y14))+exp(-G9-(Y12 + 2Y14))+exp(-G10-(Y12 + Y14))+2*exp(-G11-(Y12))-9=0

% Solve Equation 12 to 14 using fsolve.

==========================
The above is just an early guideline. Then I tried solving Equation 12 to 14 using in a new m-file. I've tried many times and many hours until I changed the unknowns, Y12, Y13, Y14 to x12, x13, x14. The outcome is I got the following ERRORS:
==========================

??? Input argument "x" is undefined.

Error in ==> myfun at 18
F=[(3*exp(-G1-(3*x(12)+8*x(13)+3*x(14))))+(2*exp(-G3-(2*x(12)+4*x(13))))+(2*exp(-G4-(2*x(12)+6*x(13))))+(3*exp(-G5-(3*x(12)+6*x(13))))+(3*exp(-G6-(3*x(12)+x(13))))+(exp(-G7-(x(12)+4*x(13))))+(exp(-G9
>>

==========================
The M-File codes are as follows:
==========================


function F=myfun(x)

G1=-340.02;
G2=-219.98;
G3=78.04767;
G4=9.674889;
G5=94.05569;
G6=40.71902;
G7=-32.28801;
G8=-2.892587;
G9=-399.21;
G10=-164.6;
G11=626.986;

% Insert x1 to x11 into Equation 12 to 14.

F=[(3*exp(-G1-(3*x(12)+8*x(13)+3*x(14))))+(2*exp(-G3-(2*x(12)+4*x(13))))+(2*exp(-G4-(2*x(12)+6*x(13))))+(3*exp(-G5-(3*x(12)+6*x(13))))+(3*exp(-G6-(3*x(12)+x(13))))+(exp(-G7-(x(12)+4*x(13))))+(exp(-G9-(x(12)+2*x(14))))+(exp(-G10-(x(12)+x(14))))+(exp(-G11-(x(12))))-4;
8*exp(-G1-(3*x(12)+8*x(13)+3*x(14)))+2*exp(-G2-(2*x(13)+x(14)))+4*exp(-G3-(2*x(12)+4*x(13)))+6*exp(-G4-(2*x(12)+6*x(13)))+6*exp(-G5-(3*x(12)+6*x(13)))+8*exp(-G6-(3*x(12)+x(13)))+4*exp(-G7-(x(12)+4*x(13)))+2*exp(-G8-(2*x(13)))-8;
3*exp(-G1-(3*x(12)+8*x(13)+3*x(14)))+exp(-G2-(2*x(13)+x(14)))+exp(-G9-(x(12)+2*x(14)))+exp(-G10-(x(12)+x(14)))+2*exp(-G11-(x(12)))-9];

% Solve Equation 12 to 14 using fsolve.

x0=[1;1;1]; %Make starting guess at the solution
options=optimset('Display','iter'); %Option to display output
[x,fval] = fsolve(@myfun,x0,options) %Call solver


end

======================
I even tried to reduce the long equations and shorten it to be like this to understand if there are any silly errors from me:
======================

function F=myfun(x)

G1=-340.02;
G2=-219.98;
G3=78.04767;
G4=9.674889;
G5=94.05569;
G6=40.71902;
G7=-32.28801;
G8=-2.892587;
G9=-399.21;
G10=-164.6;
G11=626.986;

% Insert x1 to x11 into Equation 12 to 14.

F=[(3*exp(-G1-(3*x(12)+8*x(13)+3*x(14))));
8*exp(-G1-(3*x(1)+8*x(2)+3*x(3)));
3*exp(-G1-(3*x(1)+8*x(2)+3*x(3)))];

% Solve Equation 12 to 14 using fsolve.

x0=[1;1;1]; %Make starting guess at the solution
options=optimset('Display','iter'); %Option to display output
[x,fval] = fsolve(@myfun,x0,options) %Call solver


end

======================
But still the following errors appear and I don't know else what to do after working on this code for 36 hours:
======================
??? Input argument "x" is undefined.

Error in ==> myfun at 18
F=[(3*exp(-G1-(3*x(12)+8*x(13)+3*x(14))));
 
>>

======================
It seems that I have 2 problems here which I cannot identify. I believe I have problems in (1) the x not being defined and (2) the equation has errors in it.

I really appreciate your kind input and feedback in this matter.

Thanks and best regards

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Torsten

Date: 22 May, 2012 11:23:59

Message: 8 of 12

On 22 Mai, 12:57, "Zaki " <zaki...@gmail.com> wrote:
> Dear Alan, Torsten and Roger, and others,
>
> I've tried to solve the problem using the recommended method. So far, I have put the unknowns of Y12, Y13 & Y14 in terms of equation 1 to 11.
>
> Following is the draft details. Later below is the code.
>
> function GTO1
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> %

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Zaki

Date: 22 May, 2012 12:42:07

Message: 9 of 12

Hi everybody,

After making my post just now, I tried and tried again and I get something like this...

======

>> x0=[1;1;1]; %Make starting guess at the solution
options=optimset('Display','iter'); %Option to display output
[x,fval] = fsolve(@myfun,x0,options) %Call solver

                                         Norm of First-order Trust-region
 Iteration Func-count f(x) step optimality radius
     0 4 Inf Inf 1
     1 5 Inf NaN Inf 1
     2 6 Inf NaN Inf 1
Optimizer appears to be converging to a point which is not a root.
 Norm of relative change in X is less than max(options.TolX^2,eps) but
 sum-of-squares of function values is greater than or equal to sqrt(options.TolFun)
 Try again with a new starting guess.

x =

   NaN
     1
   NaN


fval =

  1.0e+172 *

    1.1798
    0.0000
    1.1798

>>
=====
The m-files codes are:


function F=myfun(x)

G1=-340.02;
G2=-219.98;
G3=78.04767;
G4=9.674889;
G5=94.05569;
G6=40.71902;
G7=-32.28801;
G8=-2.892587;
G9=-399.21;
G10=-164.6;
G11=626.986;

% Insert x1 to x11 into Equation 12 to 14.

F=[(3*exp(-G1-(3*x(1)+8*x(2)+3*x(3))))+(2*exp(-G3-(2*x(1)+4*x(2))))+(2*exp(-G4-(2*x(1)+6*x(2))))+(3*exp(-G5-(3*x(1)+6*x(2))))+(3*exp(-G6-(3*x(1)+x(2))))+(exp(-G7-(x(1)+4*x(2))))+(exp(-G9-(x(1)+2*x(3))))+(exp(-G10-(x(1)+x(3))))+(exp(-G11-(x(1))))-4;
8*exp(-G1-(3*x(1)+8*x(2)+3*x(3)))+2*exp(-G2-(2*x(2)+x(3)))+4*exp(-G3-(2*x(1)+4*x(2)))+6*exp(-G4-(2*x(1)+6*x(2)))+6*exp(-G5-(3*x(1)+6*x(2)))+8*exp(-G6-(3*x(1)+x(2)))+4*exp(-G7-(x(1)+4*x(2)))+2*exp(-G8-(2*x(2)))-8;
3*exp(-G1-(3*x(1)+8*x(2)+3*x(3)))+exp(-G2-(2*x(2)+x(3)))+exp(-G9-(x(1)+2*x(3)))+exp(-G10-(x(1)+x(3)))+2*exp(-G11-(x(1)))-9];

% Solve Equation 12 to 14 using fsolve.

end
=====

I'm getting worried if this approach cannot solve the x1, x2 and x3 which was originally (Y12, Y13, Y14).

Any advice/recommendation?

Thanks a lot.

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Torsten

Date: 22 May, 2012 12:56:38

Message: 10 of 12

On 22 Mai, 14:42, "Zaki " <zaki...@gmail.com> wrote:
> Hi everybody,
>
> After making my post just now, I tried and tried again and I get something like this...
>
> ======
>
> >> x0=[1;1;1]; %Make starting guess at the solution
>
> options=optimset('Display','iter');

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Roger Stafford

Date: 22 May, 2012 13:27:06

Message: 11 of 12

Torsten <Torsten.Hennig@umsicht.fraunhofer.de> wrote in message <b3b4d95f-99fa-4f84-818b-a9973e96c90c@hq4g2000vbb.googlegroups.com>...
> On 22 Mai, 14:42, "Zaki " <zaki...@gmail.com> wrote:
> > Hi everybody,
> >
> > After making my post just now, I tried and tried again and I get something like this...
> >
> > ======
> >
> > >> x0=[1;1;1]; %Make starting guess at the solution
> >
> > options=optimset('Display','iter');
- - - - - - -
  Torsten, your replies are only being copied incompletely on the Mathworks newsgroup text. I think Google has made some change that Mathworks is unaware of. It seems to have something to do with the character string "=A0". Greg Heath who also uses Google Groups is having the same trouble.

Roger Stafford

Subject: Solving non-linear simultaneous equation with "Ln" in equations

From: Zaki

Date: 23 May, 2012 10:34:06

Message: 12 of 12

Dear all,

Please kindly refer to the earlier post because I will be referring to it.
After a while working on this, I managed to reach to some level.

I've now got my Y12, Y13, Y14 values after I used the approach suggested by Alan and supported by Torsten.

The following is the answer of the first round of result (command window). I hope they are correct:

=================

>> x0=[50;50;50]; %Make starting guess at the solution
options=optimset('Display','iter'); %Option to display output
[x,fval] = fsolve(@myfun,x0,options) %Call solver

                                         Norm of First-order Trust-region
 Iteration Func-count f(x) step optimality radius
     0 4 5.7821e+216 1.16e+217 1
     1 5 5.7821e+216 1 1.16e+217 1
     2 9 1.8903e+216 0.25 3.78e+216 0.25
     3 13 6.17979e+215 0.25 1.24e+216 0.25
     4 17 2.02031e+215 0.25 4.04e+215 0.25
     5 21 6.60483e+214 0.25 1.32e+215 0.25
     6 25 2.15926e+214 0.25 4.32e+214 0.25
     7 29 7.05911e+213 0.25 1.41e+214 0.25
     8 33 2.30778e+213 0.25 4.62e+213 0.25
     9 37 7.54463e+212 0.25 1.51e+213 0.25
    10 41 2.4665e+212 0.25 4.93e+212 0.25
    11 45 8.06354e+211 0.25 1.61e+212 0.25
    12 49 2.63615e+211 0.25 5.27e+211 0.25
    13 53 8.61814e+210 0.25 1.72e+211 0.25
    14 57 2.81746e+210 0.25 5.63e+210 0.25
    15 61 9.21089e+209 0.25 1.84e+210 0.25
    16 65 3.01124e+209 0.25 6.02e+209 0.25
    17 69 9.84441e+208 0.25 1.97e+209 0.25
    18 73 3.21835e+208 0.25 6.44e+208 0.25
    19 77 1.05215e+208 0.25 2.1e+208 0.25
    20 81 3.43971e+207 0.25 6.88e+207 0.25
    21 85 1.12452e+207 0.25 2.25e+207 0.25
    22 89 3.67629e+206 0.25 7.35e+206 0.25
    23 93 1.20186e+206 0.25 2.4e+206 0.25
    24 97 3.92914e+205 0.25 7.86e+205 0.25
    25 101 1.28452e+205 0.25 2.57e+205 0.25
    26 105 4.19939e+204 0.25 8.4e+204 0.25
    27 109 1.37287e+204 0.25 2.75e+204 0.25
    28 113 4.48822e+203 0.25 8.98e+203 0.25
    29 117 1.4673e+203 0.25 2.93e+203 0.25
    30 121 4.79691e+202 0.25 9.59e+202 0.25
    31 125 1.56822e+202 0.25 3.14e+202 0.25
    32 129 5.12684e+201 0.25 1.03e+202 0.25
    33 133 1.67608e+201 0.25 3.35e+201 0.25
    34 137 5.47946e+200 0.25 1.1e+201 0.25
    35 141 1.79136e+200 0.25 3.58e+200 0.25
    36 145 5.85634e+199 0.25 1.17e+200 0.25
    37 149 1.91456e+199 0.25 3.83e+199 0.25
    38 153 6.25913e+198 0.25 1.25e+199 0.25
    39 157 2.04625e+198 0.25 4.09e+198 0.25
    40 161 6.68963e+197 0.25 1.34e+198 0.25
    41 165 2.18699e+197 0.25 4.37e+197 0.25
    42 169 7.14974e+196 0.25 1.43e+197 0.25
    43 173 2.33741e+196 0.25 4.67e+196 0.25
    44 177 7.64149e+195 0.25 1.53e+196 0.25
    45 181 2.49817e+195 0.25 5e+195 0.25
    46 185 8.16707e+194 0.25 1.63e+195 0.25
    47 189 2.66999e+194 0.25 5.34e+194 0.25
    48 193 8.72879e+193 0.25 1.75e+194 0.25
    49 197 2.85363e+193 0.25 5.71e+193 0.25
    50 201 9.32915e+192 0.25 1.87e+193 0.25
    51 205 3.0499e+192 0.25 6.1e+192 0.25
    52 209 9.9708e+191 0.25 1.99e+192 0.25
    53 213 3.25967e+191 0.25 6.52e+191 0.25
    54 217 1.06566e+191 0.25 2.13e+191 0.25
    55 221 3.48387e+190 0.25 6.97e+190 0.25
    56 225 1.13895e+190 0.25 2.28e+190 0.25
    57 229 3.72349e+189 0.25 7.45e+189 0.25
    58 233 1.21729e+189 0.25 2.43e+189 0.25
    59 237 3.97959e+188 0.25 7.96e+188 0.25
    60 241 1.30101e+188 0.25 2.6e+188 0.25
    61 245 4.2533e+187 0.25 8.51e+187 0.25
    62 249 1.3905e+187 0.25 2.78e+187 0.25
    63 253 4.54584e+186 0.25 9.09e+186 0.25
    64 257 1.48613e+186 0.25 2.97e+186 0.25
    65 261 4.8585e+185 0.25 9.72e+185 0.25
    66 265 1.58835e+185 0.25 3.18e+185 0.25
    67 269 5.19266e+184 0.25 1.04e+185 0.25
    68 273 1.6976e+184 0.25 3.4e+184 0.25
    69 277 5.54981e+183 0.25 1.11e+184 0.25
    70 281 1.81435e+183 0.25 3.63e+183 0.25
    71 285 5.93152e+182 0.25 1.19e+183 0.25
    72 289 1.93914e+182 0.25 3.88e+182 0.25
    73 293 6.33949e+181 0.25 1.27e+182 0.25
    74 297 2.07252e+181 0.25 4.15e+181 0.25
    75 301 6.77551e+180 0.25 1.36e+181 0.25
Maximum number of function evaluations reached:
 increase options.MaxFunEvals.

x =

   58.2735
   50.0000
   66.5469


fval =

  1.0e+090 *

    1.8406
    0.0000
    1.8406

===================
Then, I substituted the values of Y12, Y13, Y14 into equations 1 to 11 and Equation 15.

This is how it looks like in the m-file.
===================

function F=myfunEq1to11(x)

G1=-340.02;
G2=-219.98;
G3=78.04767;
G4=9.674889;
G5=94.05569;
G6=40.71902;
G7=-32.28801;
G8=-2.892587;
G9=-399.21;
G10=-164.6;
G11=626.986;

% After replacing Y12, Y13, Y14 into Eq 1 to 11.

 %Eq1 G1 + LnY1 + (3*58.2735) + (8*50) + (3*66.5469) = 0
 %Eq2 G2 + LnY2 + (2*50) + (Y*66.5469) = 0
 %Eq3 G3 + LnY3 + (2*58.2735) + (4*50) = 0
 %Eq4 G4 + LnY4 + (2*58.2735) + (6*50.000) = 0
 %Eq5 G5 + LnY5 + (3*58.2735) + (6*50) = 0
 %Eq6 G6 + LnY6 + (3*58.2735) + (8*50) = 0
 %Eq7 G7 + LnY7 + (58.2735) + (4*50) = 0
 %Eq8 LnY8 + (2*50) = 0
 %Eq9 G9 + LnY9 + 58.2735 + (2*66.5469) = 0
%Eq10 G10 + LnY10 + 58.2735 + 66.5469 = 0
%Eq11 G11 + LnY11 + 58.2735 = 0
%Eq15 Y1 + Y2 + Y3 + Y4 + Y5 + Y6 + Y7 + Y8 + Y9 + Y10 + Y11-Y15 = 0

% Change all Y to x

F=[G1+log(x(1))+774.4612;
G2+log(x(2))+166.5469;
G3+log(x(3))+316.547;
G4+log(x(4))+416.547;
G5+log(x(5))+474.8205;
G6+log(x(6))+574.8205;
G7+log(x(7))+258.2735;
log(x(8))+100;
G9+log(x(9))+191.3673;
G10+log(x(10))+124.8204;
G11+log(x(11))+58.2735;
x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10)+x(11)-x(12)];

end

====================
And then, here is the code in the command window to call that file.
====================

>> x0=[50;50;50;50;50;50;50;50;50;50;50;50]; %Make starting guess at the solution
options=optimset('Display','iter'); %Option to display output
[x,fval] = fsolve(@myfunEq1to11,x0,options) %Call solver

                                         Norm of First-order Trust-region
 Iteration Func-count f(x) step optimality radius
     0 13 2.08172e+006 514 1
     1 26 2.07823e+006 1 510 1
     2 39 2.06961e+006 2.5 502 2.5
     3 52 2.04871e+006 6.25 481 6.25
     4 65 2.00052e+006 15.625 428 15.6
     5 78 1.90531e+006 39.0625 299 39.1
     6 91 1.80979e+006 97.6562 831 97.7
     7 92 1.80979e+006 244.141 831 244
     8 93 1.80979e+006 61.0352 831 61
     9 94 1.80979e+006 15.2588 831 15.3
    10 107 1.80901e+006 3.8147 1.65e+003 3.81
    11 108 1.80901e+006 3.8147 1.65e+003 3.81
    12 109 1.80901e+006 0.953674 1.65e+003 0.954
    13 122 1.80699e+006 0.238419 1.73e+004 0.238
    14 123 1.80699e+006 0.596046 1.73e+004 0.596
    15 124 1.80699e+006 0.149012 1.73e+004 0.149
    16 137 1.80666e+006 0.0372529 2.67e+004 0.0373
    17 138 1.80666e+006 0.0372529 2.67e+004 0.0373
    18 151 1.80587e+006 0.00931323 7.3e+004 0.00931
    19 152 1.80587e+006 0.0232831 7.3e+004 0.0233
    20 165 1.804e+006 0.00582077 7.99e+005 0.00582
    21 166 1.804e+006 0.0145519 7.99e+005 0.0146
    22 167 1.804e+006 0.00363798 7.99e+005 0.00364
    23 180 1.80391e+006 0.000909495 9.1e+005 0.000909
    24 181 1.80391e+006 0.000909495 9.1e+005 0.000909
    25 194 1.80332e+006 0.000227374 1.95e+006 0.000227
    26 195 1.80332e+006 0.000568434 1.95e+006 0.000568
    27 208 1.80234e+006 0.000142109 6.92e+006 0.000142
    28 209 1.80234e+006 0.000355271 6.92e+006 0.000355
    29 222 1.80193e+006 8.88178e-005 1.16e+007 8.88e-005
    30 223 1.80193e+006 8.88178e-005 1.16e+007 8.88e-005
    31 236 1.80108e+006 2.22045e-005 3.49e+007 2.22e-005
    32 237 1.80108e+006 5.55112e-005 3.49e+007 5.55e-005
    33 250 1.80008e+006 1.38778e-005 1.32e+008 1.39e-005
    34 251 1.80008e+006 3.46945e-005 1.32e+008 3.47e-005
    35 252 1.80008e+006 8.67362e-006 1.32e+008 8.67e-006
    36 265 1.79903e+006 2.1684e-006 5.2e+008 2.17e-006
    37 266 1.79903e+006 5.42101e-006 5.2e+008 5.42e-006
    38 279 1.79888e+006 1.35525e-006 6.11e+008 1.36e-006
    39 280 1.79888e+006 1.35525e-006 6.11e+008 1.36e-006
    40 293 1.79828e+006 3.38813e-007 1.34e+009 3.39e-007
    41 294 1.79828e+006 8.47033e-007 1.34e+009 8.47e-007
    42 307 1.79718e+006 2.11758e-007 5.24e+009 2.12e-007
    43 308 1.79718e+006 5.29396e-007 5.24e+009 5.29e-007
    44 309 1.79718e+006 1.32349e-007 5.24e+009 1.32e-007
    45 322 1.79664e+006 3.30872e-008 9.72e+009 3.31e-008
    46 323 1.79664e+006 8.27181e-008 9.72e+009 8.27e-008
    47 336 1.79585e+006 2.06795e-008 2.14e+010 2.07e-008
    48 337 1.79585e+006 5.16988e-008 2.14e+010 5.17e-008
    49 350 1.7945e+006 1.29247e-008 8.83e+010 1.29e-008
    50 351 1.7945e+006 3.23117e-008 8.83e+010 3.23e-008
    51 352 1.7945e+006 8.07794e-009 8.83e+010 8.08e-009
    52 353 1.7945e+006 2.01948e-009 8.83e+010 2.02e-009
    53 354 1.7945e+006 5.04871e-010 8.83e+010 5.05e-010
    54 355 1.7945e+006 1.26218e-010 8.83e+010 1.26e-010
    55 356 1.7945e+006 3.15544e-011 8.83e+010 3.16e-011
    56 357 1.7945e+006 7.88861e-012 8.83e+010 7.89e-012
    57 358 1.7945e+006 1.97215e-012 8.83e+010 1.97e-012
    58 359 1.7945e+006 4.93038e-013 8.83e+010 4.93e-013
Optimizer appears to be converging to a point which is not a root.
 Norm of relative change in X is less than max(options.TolX^2,eps) but
 sum-of-squares of function values is greater than or equal to sqrt(options.TolFun)
 Try again with a new starting guess.

x =

  -2.1707 + 0.0002i
   9.5520 - 0.0000i
  -0.0000 + 0.0000i
  -1.3500 + 0.0003i
  -0.8549 + 0.0053i
  -1.9792 + 0.0038i
   4.1869 - 0.0000i
   6.6367 - 0.0000i
  12.4705 - 0.0000i
   9.2936 - 0.0000i
  -3.4241 + 0.0026i
  44.5933 + 0.0000i


fval =

  1.0e+002 *

   4.3522 + 0.0314i
  -0.5118 - 0.0000i
   3.7447 + 0.0293i
   4.2652 + 0.0314i
   5.6872 + 0.0314i
   6.1622 + 0.0314i
   2.2742 - 0.0000i
   1.0189 - 0.0000i
  -2.0532 - 0.0000i
  -0.3755 - 0.0000i
   6.8649 + 0.0314i
  -0.1223 + 0.0001i
====================
After some reading through this forum and the internet, I deduced that my results are wrong. There are something wrong somewhere because I'm not getting a real value. I'm getting a complex number.

Following are my further questions/issues:

I've tried to trouble shoot this problem my changing the starting guess, but it seems like it is not working. I think maybe it is not because of the starting number.

The fact that equation 1 to 11 is having Ln (nonlinear) and equation 15 is linear makes me feel/think that maybe method is not right. I'm not sure. I research and investigated about this but I cannot get the answer.

Or, is it because there is not sufficient iterative?

I hope any of you can kindly assist/guide me on this.

I really appreciate your kind assistance.

Thanks. Thanks. Thanks a lot.

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