I have this function defined in a m-file:
function[it,xvect,xdif,fx]=bisez(a,b,nmax,toll,fun)
it=-1;
xvect=[];
xdif=[];
fx=[];
err=toll+1;
while(it<nmax && err>toll)
x=(b+a)/2;
if(fun(x)==0)
err=0;
else
err=abs(b-a)/2;
end
it=it+1;
xvect=[xvect;x];
xdif=[xdif;err];
fx=[fx:fun(x)];
if(fun(x)*fun(a)>0)
a=x;
else
b=x;
end;
end;
if(it<nmax)
fprintf('Convergence computed at step k:%d\n',it);
else
fprinf('Iteration limit reached: %d\n',it);
end
fprintf('Computed root: %-12.8f\n',xvect(it+1));
return
Then if I try to invoke it with these commands:
fun=@(x)exp(x);
a=1;
b=1.5;
nmax=1000;
toll=2;
bisez(a,b,nmax,toll,fun)
I get this error:
??? Undefined function or method 'bisez' for input arguments of type 'function_handle'.
What am I missing?
PS: I’m using Matlab 2007b
It appears it is not in your PATH when you run it.
If I run it from my PATH I get:
Outside of my PATH: