Error using feval .
古いコメントを表示
'pergjysmim.m'
function [alfa,k]=pergjysmim(fun,a,b,tol,max_iter)
% funksioni [alfa,k]=pergjysmim(fun,a,b,tol,max_iter)
% fun eshte variabel string per emrin e funksionit
% a dhe b jane skajet e segmentit qe permban rrenjen
% tol eshte gabimi (toleranca) i lejuar per rrenjen e gjetur
% max_iter eshte numri maksimal i iteracioneve te lejuara
% alfa eshte perafrimi i gjetur i rrenjes me gabim
% me te vogel se tol
% k numeron iteracionet e kryera
fa=feval(fun,a);
fb=feval(fun,b);
if sign(fa)*sign(fb)>0
error('Funksioni fun nuk ndryshon shenje ne [a,b]');
end
k=1;
while k<=max_iter
c=a+(b-a)/2; % kjo eshte me mire se c=(a+b)/2;
if abs(b-a)/2<tol
alfa=c;
return;
end
k=k+1;
fc=feval(fun,c);
if sign(fa)*sign(fc)>0
a=c; fa=fc;
elseif sign(fa)*sign(fc)<0
b=c; fb=fc;
else
disp('rrenja eshte gjetur me saktesine e precizionit te kompjuterit')
alfa=c;
return;
end
end
error('Eshte tejkaluar numri maksimal i iteracioneve te lejuara-programi pergjysmim ka mbaruar egzekutimin')
'funx.m'
function y=funx(x)
y=x^4+2*x^3-x-1;
end
Command Window
>>[zgj,iter]=pergjysmim('funx',0,1,5e-07,100)
Error using feval
Error: File: funx.m Line: 2 Column: 8
Unexpected MATLAB expression.
Error in pergjysmim (line 12)
fa=feval(fun,a); % llogarit vleren e funksionit ne a
1 件のコメント
Guillaume
2018 年 2 月 22 日
Is there by any chance another funx function that has higher priority on your path? What does
which -all funx
returns?
What happens if you call funx directly? The problem does not appear to be with feval but with your funx function.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!