I keep getting unexpected matlab error in line 1

function [xr ea iter] falsepos(func, xl, xu, es, maxit)
%function [xr ea iter] falsepos(func, xl, xu, es, maxit)
%False position method
fid = fopen('falsepos_out.txt','w');
fpritnf(fid, 'Iter.\t xl\t\t f(xl)\t\t f(xr)\t\t xu\t\t f(xu)\t\t ea\n');
if func(xl)*func(xu)>0, error('no sign change'); end
xold = xl;
for iter=1:maxit
f1 = func(x1);
fu = func(xu);
xr = xu-((func(xu).*(xu-x1))./(func(xu)-func(x1)));
fr=func(xr);
ea = abs((xr-xold)/xr)*100; %approximate relative percent error
test = f1*fr;
if test<0, xu = xr;
elseif test>0, x1 =xr;
else ea = 0;
end
fprintf(fid, '%2d\t %8.5f\t %8.5 f\t %8.5f\t %8.5f\t %8.5 f\t %8.5f\t %8.1e\n',...
iter,x1,f1,xr,fr,xU,fu,ea);
if ea<es, break;end
xold = xr;
end

Réponses (1)

You are missing an equal (=) sign.
Try this:
function [xr ea iter] = falsepos(func, xl, xu, es, maxit)

Catégories

En savoir plus sur App Building dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by