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:
Pls Help me to solve

Subject: Pls Help me to solve

From: Chirag

Date: 6 Nov, 2009 17:17:04

Message: 1 of 4

Dear Readers
I m facing problem in solving set of nonliner equations. Set contains 13 nonlinear equations and 13 variables. I've spent lots of time but unfortunately couldn't solve it....
I've tried so far solve and fsolve commands.......
When I am using solve my computer gets hanged. And fsolve is returning complex number which is practically not possible......

I've made two files

1st File:function file

function F=myfun(x)
F=[-22.47+log(x(1)/(x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10)))+(3*x(11))+(3*x(12))+(8*x(13));-24.89+log(x(2)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+x(12)+(2*x(13));-49.539+log(x(3)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+x(11)+(2*x(12));-0.0574+log(x(4)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+(2*x(13));-24.597+log(x(5)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+x(11)+x(12);-0.7027+log(x(6)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+x(11)+(4*x(13));-32.59+log(x(7)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+(2*x(11))+(2*x(12))+(4*x(13));-10.927+log(x(8)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+x(11)+x(12)+(4*x(13));-4.635+log(x(9)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+(2*x(11))+(x(12))+(6*x(13));-7.5188+log(x(10)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x
(10))))+(2*x(11))+(x(12))+(4*x(13));3*x(1)+x(3)+x(5)+x(6)+2*x(7)+x(8)+2*x(9)+2*x(10)-0.1002;3*x(1)+x(2)+2*x(3)+x(5)+2*x(7)+x(8)+x(9)+x(10)-1.6332;8*x(1)+2*x(2)+2*x(4)+4*x(6)+4*x(7)+4*x(8)+6*x(9)+4*x(10)-3.3332]


2nd file: calls the function

clc
clear all
x0=[2;13;13;13;13;13;13;13;13;13;1;1;1] %initial guess
options=optimset('Display','iter'); % Option to display output
[x,fval] = fsolve(@myfun,x0,options) % Call optimizer

It would be great help if u can give me some guidance to solve it.....


Thank You

Subject: Pls Help me to solve

From: Torsten Hennig

Date: 7 Nov, 2009 11:51:04

Message: 2 of 4

> Dear Readers
> I m facing problem in solving set of nonliner
> equations. Set contains 13 nonlinear equations and 13
> variables. I've spent lots of time but unfortunately
> couldn't solve it....
> I've tried so far solve and fsolve commands.......
> When I am using solve my computer gets hanged. And
> fsolve is returning complex number which is
> practically not possible......
>
> I've made two files
>
> 1st File:function file
>
> function F=myfun(x)
> F=[-22.47+log(x(1)/(x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)
> +x(8)+x(9)+x(10)))+(3*x(11))+(3*x(12))+(8*x(13));-24.8
> 9+log(x(2)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x
> (9)+x(10))))+x(12)+(2*x(13));-49.539+log(x(3)/((x(1)+x
> (2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+x(11)+
> (2*x(12));-0.0574+log(x(4)/((x(1)+x(2)+x(3)+x(4)+x(5)+
> x(6)+x(7)+x(8)+x(9)+x(10))))+(2*x(13));-24.597+log(x(5
> )/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10)
> )))+x(11)+x(12);-0.7027+log(x(6)/((x(1)+x(2)+x(3)+x(4)
> +x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+x(11)+(4*x(13));-32
> .59+log(x(7)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)
> +x(9)+x(10))))+(2*x(11))+(2*x(12))+(4*x(13));-10.927+l
> og(x(8)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)
> +x(10))))+x(11)+x(12)+(4*x(13));-4.635+log(x(9)/((x(1)
> +x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+(2*x
> (11))+(x(12))+(6*x(13));-7.5188+log(x(10)/((x(1)+x(2)+
> x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x
> (10))))+(2*x(11))+(x(12))+(4*x(13));3*x(1)+x(3)+x(5)+x
> (6)+2*x(7)+x(8)+2*x(9)+2*x(10)-0.1002;3*x(1)+x(2)+2*x(
> 3)+x(5)+2*x(7)+x(8)+x(9)+x(10)-1.6332;8*x(1)+2*x(2)+2*
> x(4)+4*x(6)+4*x(7)+4*x(8)+6*x(9)+4*x(10)-3.3332]
>
>
> 2nd file: calls the function
>
> clc
> clear all
> x0=[2;13;13;13;13;13;13;13;13;13;1;1;1] %initial
> guess
> options=optimset('Display','iter'); % Option to
> display output
> [x,fval] = fsolve(@myfun,x0,options) % Call
> optimizer
>
> It would be great help if u can give me some guidance
> to solve it.....
>
>
> Thank You

In order to avoid complex number solutions, you should
be careful that you do not take the log of a negative
number during iteration. Restrict your solution variables
to be positive or solve in the squares of your solution
variables.

Best wishes
Torsten.

Subject: Pls Help me to solve

From: Chirag Dave

Date: 8 Nov, 2009 18:55:03

Message: 3 of 4

Thanks Torsten for spending time to answer my question. By assuming square of the variable I could resolve the problem of getting complex number, but still in fsolve it asks for assuming some different initial guess and i changed intial guess no. of times but I couldn't solve it. The problem is getting converged at the point which is not root of the given problem---such sort of error I m getting all the time and it's asking for new initial guess 2 solve......What to do now?

Thank You



Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <2126357853.29693.1257594694977.JavaMail.root@gallium.mathforum.org>...
> > Dear Readers
> > I m facing problem in solving set of nonliner
> > equations. Set contains 13 nonlinear equations and 13
> > variables. I've spent lots of time but unfortunately
> > couldn't solve it....
> > I've tried so far solve and fsolve commands.......
> > When I am using solve my computer gets hanged. And
> > fsolve is returning complex number which is
> > practically not possible......
> >
> > I've made two files
> >
> > 1st File:function file
> >
> > function F=myfun(x)
> > F=[-22.47+log(x(1)/(x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)
> > +x(8)+x(9)+x(10)))+(3*x(11))+(3*x(12))+(8*x(13));-24.8
> > 9+log(x(2)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x
> > (9)+x(10))))+x(12)+(2*x(13));-49.539+log(x(3)/((x(1)+x
> > (2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+x(11)+
> > (2*x(12));-0.0574+log(x(4)/((x(1)+x(2)+x(3)+x(4)+x(5)+
> > x(6)+x(7)+x(8)+x(9)+x(10))))+(2*x(13));-24.597+log(x(5
> > )/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10)
> > )))+x(11)+x(12);-0.7027+log(x(6)/((x(1)+x(2)+x(3)+x(4)
> > +x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+x(11)+(4*x(13));-32
> > .59+log(x(7)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)
> > +x(9)+x(10))))+(2*x(11))+(2*x(12))+(4*x(13));-10.927+l
> > og(x(8)/((x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)
> > +x(10))))+x(11)+x(12)+(4*x(13));-4.635+log(x(9)/((x(1)
> > +x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10))))+(2*x
> > (11))+(x(12))+(6*x(13));-7.5188+log(x(10)/((x(1)+x(2)+
> > x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x
> > (10))))+(2*x(11))+(x(12))+(4*x(13));3*x(1)+x(3)+x(5)+x
> > (6)+2*x(7)+x(8)+2*x(9)+2*x(10)-0.1002;3*x(1)+x(2)+2*x(
> > 3)+x(5)+2*x(7)+x(8)+x(9)+x(10)-1.6332;8*x(1)+2*x(2)+2*
> > x(4)+4*x(6)+4*x(7)+4*x(8)+6*x(9)+4*x(10)-3.3332]
> >
> >
> > 2nd file: calls the function
> >
> > clc
> > clear all
> > x0=[2;13;13;13;13;13;13;13;13;13;1;1;1] %initial
> > guess
> > options=optimset('Display','iter'); % Option to
> > display output
> > [x,fval] = fsolve(@myfun,x0,options) % Call
> > optimizer
> >
> > It would be great help if u can give me some guidance
> > to solve it.....
> >
> >
> > Thank You
>
> In order to avoid complex number solutions, you should
> be careful that you do not take the log of a negative
> number during iteration. Restrict your solution variables
> to be positive or solve in the squares of your solution
> variables.
>
> Best wishes
> Torsten.

Subject: Pls Help me to solve

From: Miroslav Balda

Date: 8 Nov, 2009 23:05:03

Message: 4 of 4

SNIP

Hi,
I tried to solve your task, because it is rather complicated and I wanted to test my function LMFnlsq. However, the code of your function is rather confused. I have changed it into more lucid form. I am not sure whether I have not introduced an error.
Nevertheless , the following code solved the example in every attempt:

% chirag.m 2009-11-08
[x,fval,cnt] = LMFnlsq(@myfun,rand(13,1),'Display',-20); % Call optimizer
format short e
x = x.*x

% function file:
function res = myfun(x)
x = x.*x;
sumx = sum(x(1:10));
res = [-22.47+log(x(1)/sumx)+3*x(11)+3*x(12)+8*x(13)
     -24.89+log(x(2)/sumx)+x(12)+2*x(13)
     -49.539+log(x(3)/sumx)+x(11)+2*x(12)
     -0.0574+log(x(4)/sumx)+2*x(13)
     -24.597+log(x(5)/sumx)+x(11)+x(12)
     -0.7027+log(x(6)/sumx)+x(11)+4*x(13)
     -32.59+log(x(7)/sumx)+2*x(11)+2*x(12)+4*x(13)
     -10.927+log(x(8)/sumx)+x(11)+x(12)+4*x(13)
     -4.635+log(x(9)/sumx)+2*x(11)+x(12)+6*x(13)
     -7.5188+log(x(10)/sumx)+2*x(11)+x(12)+4*x(13)
     3*x(1)+x(3)+x(5)+x(6)+2*x(7)+x(8)+2*x(9)+2*x(10)-0.1002
     3*x(1)+x(2)+2*x(3)+x(5)+2*x(7)+x(8)+x(9)+x(10)-1.6332
     8*x(1)+2*x(2)+2*x(4)+4*x(6)+4*x(7)+4*x(8)+6*x(9)+4*x(10)-3.3332];

The above code is much better organized, so that you may see, the form of equations. more over, what is once evaluated doesn't need be evaluated more times (sumx).
A solution has been reached always starting from a random initial estimate. If the accuracy is low, you may change the default one by a new option. Maybe that a requirement on positivness of all x is too strict, because the sum of squares dropped down only by one order. The reason could be also in an error in equations.

Hope it helps.

Mira

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