Path: news.mathworks.com!not-for-mail
From: "Zaki " <zaki.yz@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Solving non-linear simultaneous equation with "Ln" in equations
Date: Tue, 22 May 2012 10:57:07 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 161
Message-ID: <jpfre3$jgm$1@newscl01ah.mathworks.com>
References: <jp5lp1$m4d$1@newscl01ah.mathworks.com> <jpd5hc$kad$1@newscl01ah.mathworks.com> <jpe4ku$cu7$1@newscl01ah.mathworks.com> <jpfju3$ksf$1@newscl01ah.mathworks.com>
Reply-To: "Zaki " <zaki.yz@gmail.com>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1337684227 19990 172.30.248.37 (22 May 2012 10:57:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 22 May 2012 10:57:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3493338
Xref: news.mathworks.com comp.soft-sys.matlab:768575

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