MATLAB: I cannot get this to work…I keep getting errors all over the place. Could someone kindly explain

false-position

function Burke_FP()
clear
clc
t1 = input('Please input your upper bounds')
f1 = myfunc(t1);
t2 = input('Please input your lower bounds')
f2 = myfunc(t2);
t = linspace (t1,t2,100);
error = 10;
f = myfunc(t);
plot(t,f)
while error > 1e-4
tr = t2 - f2*(t1 - t2)/(f1-f2);
fr = myfunc(tr);
if sign(fr) == f1
t1 = tr;
f1 = fr;
else
t2 = tr;
f2 = fr;
end
%recompute error
error = abs(fr);
end
tr
end
function out = myfunc(in)
in.^2-5
end

Best Answer

You have
if sign(fr) == f1
but sign(fr) is going to be -1 (exactly), 0 (exactly), or +1 (exactly), none of which are likely to be exactly equal to fl.