2012-08-22 4 views
0

에 인수로 함수를 전달하는 내가 가지고 m-파일에 정의 된이 기능 : 나는 이러한 명령으로 호출하려고하면 다음어떻게 matlab에

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 

:

[email protected](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

답변

5

을 사용하고 당신이 그것을 실행할 때 당신의 PATH에없는 나타납니다. 내 PATH에서 실행할 경우

내가 얻을 : 내 PATH의

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

    ans = 

     0 

외부 :

>> bisez(a,b,nmax,toll,fun) 
    Undefined function 'bisez' for input arguments of type 'function_handle'. 
+0

본부를, 당신이 바로, 당신을 감사합니다! – Aslan986