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!