1

この関数を m ファイルで定義しています。

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

次に、これらのコマンドでそれを呼び出そうとすると:

fun=@(x)exp(x);
a=1;
b=1.5;
nmax=1000;
toll=2;
bisez(a,b,nmax,toll,fun)

次のエラーが表示されます。

??? Undefined function or method 'bisez' for input arguments of type 'function_handle'.

私は何が欠けていますか?

PS:私は使用していますMatlab 2007b

4

1 に答える 1

5

実行すると、PATHにないようです。

PATH から実行すると、次のようになります。

>> bisez(a,b,nmax,toll,fun)
   Convergence computed at step k:0
   Computed root: 1.25000000  

   ans =

        0

私のPATHの外:

>> bisez(a,b,nmax,toll,fun)
   Undefined function 'bisez' for input arguments of type 'function_handle'.
于 2012-08-22T10:31:08.400 に答える