converting the fzero function of MATLAB (Brent Method) to C code -
i trying write similar function in c 1 in matlab called fzero, found out fzero uses brent method in order find roots.
t=fzero(myfunction,cathreshold); this function need, suppose give me 0 of myfunction near cathreshold.
when tried implement brent method in order find required result figured out in addition myfunction need 2 inputs a , b.
b considered current guess root of myfunction. a point such myfunction(a) , myfunction(b) have opposite signs, interval [a, b] contains solution.
i can write c code of brent method knowing inputs couldn't write 1 knowing function, , called cathreshold. how should choose value of a ?!
could explains me how fzero works maybe help!
from documentation of fzero(fun,x0), can see x0 should within interval [a,b] such f(a) , f(b) have different signs.
by typing edit fzero in command window, can open function itself. may write own version, looking through non-obfuscated code. @ top of function see description:
% x = fzero(fun,x0) tries find 0 of function fun near x0, % if x0 scalar. first finds interval containing x0 % function values of interval endpoints differ in sign, searches % interval zero. so fzero still uses interval [a,b], finds interval surrounding scalar x0. note can pass interval fzero, detailed second input option:
% x = fzero(fun,x0), x0 vector of length 2, assumes x0 % finite interval sign of fun(x0(1)) differs sign of % fun(x0(2)). error occurs if not true. specifically, see part of function begins
% interval input where see processing of 2 above input options
if (numel(x) == 2) % ... = x(1); savea=a; b = x(2); saveb=b; % ... elseif (numel(x) == 1) % ... % method calculating , b % ... end
Comments
Post a Comment