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

1 次查看(过去 30 天)
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.

回答(1 个)

Walter Roberson
Walter Roberson 2013-4-19
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 个评论
Nic
Nic 2013-4-19
编辑:Nic 2013-4-19
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.'

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by