Got Questions? Get Answers.
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 15 nonliear equations and 15 unknowns

Subject: Solving 15 nonliear equations and 15 unknowns

From: alzack

Date: 28 May, 2012 11:55:00

Message: 1 of 2

Hi

I have 15 equations and 15 unknowns. Eq 1 to 11 has Ln which makes it
a nonlinear. Eq 12-15 is linear. Unknowns are x(1), x(2), x(3)......
x(15).

after testing the code in the command window, I got this error:

==============
>> x0 = [5;5;5;5;5;5;5;5;5;5;5;5;5;5;5]; % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
[x,fval] = fsolve(@f2,x0,options) % Call solver
??? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> f2 at 18
Y(12)=[3 0 2 2 3 3 1 0 1 1 1]*x(1:11)'-0.041121;

Error in ==> fsolve at 254
            fuser = feval(funfcn{3},x,varargin{:});

Caused by:
    Failure in initial user-supplied objective function evaluation.
FSOLVE cannot
    continue.

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

I have spent countless hours trying to fix the errors but I just
cannot get it.

Here is the m-file code:
==============

function Y=f2(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;
R=8.315;T=573;
summation=sum(x(1:11)); % equation #15
RT=1/(R*T); % Less Computation~Less Error
Y(1)=RT*(G1+(1/RT)*log(x(1)/summation)+3*x(12)+8*x(13)+3*x(14));
Y(2)=RT*(G2+(1/RT)*log(x(2)/summation)+2*x(13)+x(14));
Y(3)=RT*(G3+(1/RT)*log(x(3)/summation)+2*x(12)+4*x(13));
Y(4)=RT*(G4+(1/RT)*log(x(4)/summation)+2*x(12)+6*x(13));
Y(5)=RT*(G5+(1/RT)*log(x(5)/summation)+3*x(12)+6*x(13));
Y(6)=RT*(G6+(1/RT)*log(x(6)/summation)+3*x(12)+8*x(13));
Y(7)=RT*(G7+(1/RT)*log(x(7)/summation)+x(12)+4*x(13));
Y(8)=log(x(8)/summation)+2*x(13)*RT;
Y(9)=RT*(G9+(1/RT)*log(x(10)/summation)+x(12)+x(14));
Y(10)=RT*(G10+(1/RT)*log(x(9)/summation)+x(12)+2*x(14));
Y(11)=RT*(G11+(1/RT)*log(x(11)/summation)+x(12));
Y(12)=[3 0 2 2 3 3 1 0 1 1 1]*x(1:11)'-0.041121;
Y(13)=[8 2 4 6 6 8 4 2]*x(1:8)'-0.436582;
Y(14)=[3 1 0 0 0 0 0 0 1 2]*x(1:10)'-0.204584;
%Y(15)=summation;
==============

Any help is very much appreciated.

Thanks.

Subject: Solving 15 nonliear equations and 15 unknowns

From: Roger Stafford

Date: 28 May, 2012 12:33:07

Message: 2 of 2

alzack <zaki.yz@gmail.com> wrote in message <a0910487-918e-4e3b-92e1-99c4eaa202ab@s9g2000vbg.googlegroups.com>...
> ??? Error using ==> mtimes
> Inner matrix dimensions must agree.
> Error in ==> f2 at 18
> Y(12)=[3 0 2 2 3 3 1 0 1 1 1]*x(1:11)'-0.041121;
- - - - - - - - - -
  Since your x0 estimate is a column vector, presumably the x which 'fsolve' sends to @f2 will also be a column vector. The fact that 1:11 is a row vector does not make x(1:11) a row vector so it is incorrect to take its transpose x(1:11)' as you have done. That is also true of x(1:8)' and x(1:10)' in Y(13) and Y(14).

  That is what the error message is trying to tell you:

"??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> f2 at 18
Y(12)=[3 0 2 2 3 3 1 0 1 1 1]*x(1:11)'-0.041121;"

Roger Stafford

Tags for this Thread

No tags are associated with 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