Link to home
Start Free TrialLog in
Avatar of vinzybuoy
vinzybuoy

asked on

Matlab fzero help

Hi,
 I am trying to solve a nonlinear equation using matlab. The function
that I am using is 'fzero'. I start with an initial guess 'x0'. Due to
the nature of the nonlinear equation, I always get the final answer
less than x0, which is physically meaningless.

 There are values greater than x0 which satisfy the equation. However,
I always get lesser values. Could someone please tell me how to
write a code for that.

Here is my code which returns lesser values:

options=optimset('TolX',1e-20);
x0=33e-20;
x1=fzero('f',x0,options);

'f' is function which contains the nonlinear equation.
Thanks a lot!



Avatar of GwynforWeb
GwynforWeb
Flag of Canada image

vinzybuoy
  Try using x0 large and positive. Othwerwise show us what the nonlinear equation is there are other ways of doing this.

GwynforWeb
vinzybuoy,
  Perhaps I should explain in more detail. Matlab's fzero uses Newton's method for solving the equation. If the equation has multiple roots then different starting values will in general tend to different roots. If you know what your function roughly looks like and understand graphically how Newton's method works you can choose your starting value so fzero tends to the root you are looking for.

GwynforWeb
Avatar of vinzybuoy
vinzybuoy

ASKER

Hi GwynforWeb,
 If you need the nonlinear equations here it is. It is of the form:

   y=f(Alpha)

These are the constants:

SPr = 15e-3;
Concen = 3.2;
T = 300;
z = 1;

Pi = 3.1415926;
kB = 1.381E-23;

B11 = -367e-20;
Eps = 78;
e = 1.602e-19;
d = 0.000000000405;
Eps_s = 35.4;

a=25e-20;
r=(a/Pi)^0.5;
k = ((8 * Pi * e * e) / (kB * T * Eps))^0.5;


C1 = kB * T;
C2 = ((Eps * k) / Pi) * ((C1 / e)) ^ 2;
C3 = ((2 * Pi * e) / (Eps * k * C1)) ^ 2;
C4 = (2 * Pi * d) / Eps_s;
C  = 0.1

%% C can vary from 0.1 to 10.0. It is a concentration value
%% of a compound. For different values of C, you will get
%% different values of Alpha. It is a inversely
%% proportionally relationship.

And this is the equation:

y=2 * log(C) - log(abs(1 / (Alpha - a))) - (a + 2 * Pi * r * r) / (Alpha - a) - ((Pi * a * r * r) / (Alpha - a) ^ 2) - (2 * B11 / Alpha) - 2 * z * log(abs(((sqrt(C3) * e * z / Alpha) + sqrt(1 + ((sqrt(C3) * e * z / Alpha)) ^ 2)))) - ((2 * C4) / C1) * ((z * e) ^ 2) / Alpha - 59;



Alpha is a parmeter which shud be greater than a=25e-20 and should not exceed abt 50e-20. But I always get values of Alpha less than a.

Can I define something in optimset so that Alpha is returned only when it is greater than a?
Also, could you pls explain me in "english", wht exactly is the meaning of TolX and TolFun in optimset? :)

thanx a lot!


vinzybuoy
  You may be having round off errors, I will solve the system for all its roots this evening when I have time to check the roots are where you think they are. ( I have software to do that)
ASKER CERTIFIED SOLUTION
Avatar of GwynforWeb
GwynforWeb
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

vinzybuoy
It does not matter if it is base e or 10. Here are some values of y(alpha)for  different values of c and for Alpha from Alpha = 261E-20  at interavls of 2E-20. As you can see the function is no where near approaching zero

c=1
-704.982370388223  -210.319443835839  -160.924841699412  -146.211276245996  -140.010772788942  -136.930868911307  -135.262449845303  -134.319721207247  -133.782934191503  -133.486736079215  -133.338939192559  -133.285161177615  -133.291899846305  

c=3
-702.785145810887  -208.122219258502  -158.727617122075  -144.01405166866  -137.813548211605  -134.73364433397  -133.065225267967  -132.122496629911  -131.585709614167  -131.289511501879  -131.141714615223  -131.087936600278  -131.094675268969  

c=5
-701.763494563355  -207.10056801097  -157.705965874543  -142.992400421128  -136.791896964073  -133.711993086438  -132.043574020435  -131.100845382379  -130.564058366635  -130.267860254347  -130.120063367691  -130.066285352746  -130.073024021437

c=8
-700.823487304864  -206.160560752479  -156.765958616052  -142.052393162637  -135.851889705582  -132.771985827947  -131.103566761944  -130.160838123887  -129.624051108143  -129.327852995856  -129.1800561092  -129.126278094255  -129.133016762946

c=10
-700.377200202235  -205.714273649851  -156.319671513424  -141.606106060008  -135.405602602953  -132.325698725318  -130.657279659315  -129.714551021259  -129.177764005515  -128.881565893227  -128.733769006571  -128.679990991627  -128.686729660317    
Alpha = 2.61E-20  at interavls of 2E-20
Stiil can not get it right "Alpha = 26.1E-20  at interavls of 2E-20 "
I checked it out too. You are right. There *are* no solutions such that alpha > 25e-20.

Anywayz, thanx a lot for you help!
hi vinz,

GwynforWeb did answer your question so you should
take one of the Gwyn comments as an answer with
an A grade.

leo

This question appears to have been abandoned. In the absence of comments to the contrary, the comment of GwynforWeb will be accepted as the answer.

Please leave your comments on this issue here.

Netminder
EE Admin
Force-accepted.

Netminder
EE Admin