?
Solved

Matlab fzero help

Posted on 2003-03-30
12
Medium Priority
?
1,873 Views
Last Modified: 2008-02-01
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!



0
Comment
Question by:vinzybuoy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
  • 2
  • +1
12 Comments
 
LVL 31

Expert Comment

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

GwynforWeb
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 8236245
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
0
 

Author Comment

by:vinzybuoy
ID: 8237456
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!


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:GwynforWeb
ID: 8239522
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)
0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 1000 total points
ID: 8241062
vinzybuoy,
   The reason you are not getting any solutions in the ranges c=0.1 to 10 and alpha  a=25e-20 to 50e-20 is that for the equation you have posted there are no solutions in that range. Are you meaning log to mean base 10 or e in your equation.

GwynforWeb
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 8241367

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    
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 8241391
Alpha = 2.61E-20  at interavls of 2E-20
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 8241396
Stiil can not get it right "Alpha = 26.1E-20  at interavls of 2E-20 "
0
 

Author Comment

by:vinzybuoy
ID: 8244794
I checked it out too. You are right. There *are* no solutions such that alpha > 25e-20.

Anywayz, thanx a lot for you help!
0
 
LVL 3

Expert Comment

by:leojl
ID: 8290185
hi vinz,

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

leo

0
 
LVL 5

Expert Comment

by:Netminder
ID: 8308506
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
0
 
LVL 5

Expert Comment

by:Netminder
ID: 8349585
Force-accepted.

Netminder
EE Admin
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question