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:
Please help on Solving Non Linear Equations

Subject: Please help on Solving Non Linear Equations

From: Jie

Date: 21 Oct, 2010 21:15:07

Message: 1 of 2

Hello,

I am trying to solve the equations below with fslove where w0=[0.81,1]

function F=CFM(w)
GammaL=[0.1205, 0.2034, 0.3129];
GammaC=[0.3862,0.3249,0.3078];
GammaS=[0.5067, 0.5283, 0.6206];
Output=[3511,46176,72721];
Theta=[0.3,0.4,0.5];
FactorS=[33746,36582];
F=[((w(1)^(1-Theta(1))*(GammaL(1)/GammaS(1))+(w(2)^(1-Theta(1)))*(GammaC(1)/GammaS(1)))^(Theta(1)/(1-Theta(1))))*(w(1)^(-Theta(1)))*GammaL(1)*Output(1)+((w(1)^(1-Theta(2))*(GammaL(2)/GammaS(2))+(w(2)^(1-Theta(2)))*(GammaC(2)/GammaS(2)))^(Theta(2)/(1-Theta(2))))*(w(1)^(-Theta(2)))*GammaL(2)*Output(2)+((w(1)^(1-Theta(3))*(GammaL(3)/GammaS(3))+(w(2)^(1-Theta(3)))*(GammaC(3)/GammaS(3)))^(Theta(3)/(1-Theta(3))))*(w(1)^(-Theta(3)))*GammaL(3)*Output(3)-FactorS(1);
   ((w(1)^(1-Theta(1))*(GammaL(1)/GammaS(1))+(w(2)^(1-Theta(1)))*(GammaC(1)/GammaS(1)))^(Theta(1)/(1-Theta(1))))*(w(2)^(-Theta(1)))*GammaC(1)*Output(1)+((w(1)^(1-Theta(2))*(GammaL(2)/GammaS(2))+(w(2)^(1-Theta(2)))*(GammaC(2)/GammaS(2)))^(Theta(2)/(1-Theta(2))))*(w(2)^(-Theta(2)))*GammaC(2)*Output(2)+((w(1)^(1-Theta(3))*(GammaL(3)/GammaS(3))+(w(2)^(1-Theta(3)))*(GammaC(3)/GammaS(3)))^(Theta(3)/(1-Theta(3))))*(w(2)^(-Theta(3)))*GammaC(3)*Output(3)-FactorS(2)];
end

I got the following message saying

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.

Does this mean there is no solution? Could anyone help please? is there another to do it? Many Thanks in Advance.

Jie

Subject: Please help on Solving Non Linear Equations

From: Miroslav Balda

Date: 22 Oct, 2010 08:10:06

Message: 2 of 2

"Jie " <jz286@cam.ac.uk> wrote in message <i9qagr$8vr$1@fred.mathworks.com>...

SNIP

Hi Jie,
I tried to solve your problem with my function LMFnlsq (FEX Id. 17534). I did not changed your function, but splitting the equations into more lines to be more readable. I call you function from the command window:
   for k=1:10, [w,ssq,cnt] = LMFnlsq(@CFM,rand(2,1),'Display',-100); end
getting the following output:

******************************************************************* itr nfJ SUM(r^2) x dx
******************************************************************* 0 1 1.3649e+008 1.9872e-001 0.0000e+000
                        6.0379e-001 0.0000e+000
 
   5 5 1.6508e+006 -3.7316e+007 0.0000e+000
                       -4.1858e+007 0.0000e+000
*******************************************************************
  itr nfJ SUM(r^2) x dx
*******************************************************************
   0 1 3.6414e+007 2.7219e-001 0.0000e+000
                        1.9881e-001 0.0000e+000
 
   6 46 6.6996e+005 2.1943e-001 1.8379e-008
                        2.6800e-001 3.6571e-008
*******************************************************************
  itr nfJ SUM(r^2) x dx
*******************************************************************
   0 1 8.4717e+009 1.5274e-002 0.0000e+000
                        7.4679e-001 0.0000e+000
 
  40 58 6.6997e+005 2.3048e+005 -1.6868e-010
                        2.8157e+005 -3.3263e-007
*******************************************************************
  itr nfJ SUM(r^2) x dx
*******************************************************************
   0 1 4.3729e+007 4.4510e-001 0.0000e+000
                        9.3181e-001 0.0000e+000
 
   7 53 6.6996e+005 6.1641e-001 -1.3566e-007
                        7.5284e-001 -1.4849e-007
*******************************************************************
  itr nfJ SUM(r^2) x dx
*******************************************************************
   0 1 1.3354e+007 4.6599e-001 0.0000e+000
                        4.1865e-001 0.0000e+000
 
   6 50 6.6996e+005 4.0986e-001 1.7586e-009
                        5.0057e-001 6.6659e-008
*******************************************************************
  itr nfJ SUM(r^2) x dx
*******************************************************************
   0 1 6.3464e+007 8.4622e-001 0.0000e+000
                        5.2515e-001 0.0000e+000
 
  48 70 6.6996e+005 5.4182e+005 2.0177e-006
                        6.6180e+005 1.3624e-006
*******************************************************************
  itr nfJ SUM(r^2) x dx
*******************************************************************
   0 1 1.6839e+008 2.0265e-001 0.0000e+000
                        6.7214e-001 0.0000e+000
 
   4 6 1.6642e+007 1.3048e+006 -1.5237e-008
                        2.2276e+006 9.7551e-008
*******************************************************************
  itr nfJ SUM(r^2) x dx
*******************************************************************
   0 1 8.3611e+009 8.3812e-001 0.0000e+000
                        1.9640e-002 0.0000e+000
 
  45 66 6.6996e+005 4.2723e+005 1.6085e-006
                        5.2184e+005 1.7937e-009
*******************************************************************
  itr nfJ SUM(r^2) x dx
*******************************************************************
   0 1 8.6168e+007 6.8128e-001 0.0000e+000
                        3.7948e-001 0.0000e+000
 
  47 66 6.6996e+005 1.5591e+006 -2.1807e-005
                        1.9041e+006 -1.1320e-005
*******************************************************************
  itr nfJ SUM(r^2) x dx
*******************************************************************
   0 1 6.8618e+007 8.3180e-001 0.0000e+000
                        5.0281e-001 0.0000e+000
 
  13 28 6.6996e+005 9.8081e+004 1.9142e-005
                        1.1979e+005 1.6852e-005

The results come from 10 solutions of the problem random starting values w0. Often solution gives the value of sum of squares of residuals ssq = 6.6996e5, however, from different points of solution. It suggests that the function has a valey with constant value of ssq.

Your code is not optimized, because constant parameters are set every times the function CMF is called. The improvement is either
  1. to declare those variables as global, or (better)
  2. to build a driver function, where those variables are assigned once, and the function LMFnlsq call is placed there. In this case, the function CMF should be a nested function of the driver.

Hope it helps.

Mira

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