MATLAB: I am unable to get the result due to error, and dont know how to fix it. please reply

modified regula falsi method

F =inline('x^3-2*x-3');
a=1; b=2; nmax=20;
Fa=F(a); Fb=F(b);
if Fa*Fb<0
wn=(a*F(b) - b*F(a))/(F(b)-F(a));
c = Fa;
g = Fb;
wo = a;
while(1)
wn=(a*g - b*c)/(g-c);
if c*F(wn)<0
b=wn;
g=F(wn);
if F(wo)*F(wn)>0
c=c/2;
end
else
a=wn;
F=F(wn);
if F(wo)*F(wn)>0
g=g/2;
end
end
% if abs((wn-wo)/wn)<(.5*10^(-n))
%break
%end
end
end

Best Answer

The problem is this line:
F=F(wn)
because you reassign the variable F, and so it stops being a function that you can call. So the next time you try to call what you think is a function, it is actually a scalar numeric which you try to access with what MATLAB thinks is indexing.
IMPORTANT Note that you should define F using an anonymous function:
F = @(x)x^3-2*x-3;
and not using an inline function: inline functions are inefficient and obsolete, and their documentation page clearly states: " inline will be removed in a future release. Use Anonymous Functions instead."
Question (because I am curious): who taught you to use the obsolete inline ?