fzero help please I need value of y...the complete code is as follows

1 view (last 30 days)
I wrote following code in matlab.
% declare global variables
global bcr vc locr rc rb wb
% define given parameters
bcr = 0.713;
vc = 0.18;
locr=0.092;
rc = 0.056;
rb = 0.008;
wb = 1.19;
% compute the root of wc f(wc)=0.0 using fzer0 function
[y,fval,exitflag,output] = fzero('myfun_y',[0.008,0.056])
function file is as follows:
% function file to calculate value of y at which f(y) = 0.0 using fzero
function f = myfun_y(y)
% declare global variables
global locr rb vc rc wb bcr
% define function f(y)
f1 = ((y-rb)/(locr*(locr-y)*(locr-rb)))+((1/locr^2)*log((y*(locr-rb))/(rb*(locr-y))));
f2 = (y*(locr-y))*((1.+vc)+(1.-vc^2)*(rc^2-y^2)/(rc^2+y^2));
f3 = wb*bcr;
f = f1*f2-f3;
end
*When I run, this code I got following message.
Error using fzero (line 233)
FZERO cannot continue because user supplied function_handle ==> myfun_y
failed with the error below.
Not enough input arguments.
Error in compute_y (line 22)
[y,fval,exitflag,output] = fzero('myfun_y',[0.008,0.056]) *
ANy idea, what is going on...I need value of y between 0.008 and 0.56...
*I am hating fzero now...it is giving me hard time.

Answers (1)

Walter Roberson
Walter Roberson on 19 Apr 2013
Experiment with replacing
[y,fval,exitflag,output] = fzero('myfun_y',[0.008,0.056])
with
[y,fval,exitflag,output] = fzero(@myfun_y, [0.008,0.056])
  3 Comments
Walter Roberson
Walter Roberson on 19 Apr 2013
It is the log* that is the problem. Not enough input arguments to log.
Nic
Nic on 19 Apr 2013
Edited: Nic on 19 Apr 2013
Hi, I change log* ... and run the program... it is giving right value of y which is 0.008 when wb =0.0.... But when I change the value of wb to 1.0..I got following error message.... I need to solve this problem please help. thank you so much.
(when wb =1.0)** Error using fzero (line 274) The function values at the interval endpoints must differ in sign. Error in compute_y (line 23) [y,fval,exitflag,output] = fzero(@myfun_y,[0.008, 0.056])
  • (when wb =0.0)** y =
0.0080
fval =
0
exitflag =
1
output =
intervaliterations: 0
iterations: 0
funcCount: 2
algorithm: 'bisection, interpolation'
message: 'Zero find terminated.'

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!