Hello All,

I am need in need of some help with creating this regula falsi function. Below is the function I have created along with the definitions for the variables in the function, however when trying to run in the command prompt, I get the error "Subscript indices must either be real positive integers or logicals" and points to the line with f(b) = fun(b). I don't really understand what this error means and what exactly its looking at.

FYI, I am new to matlab, so any help would be much appreciated.

Thank you.

`fun = @(in)(in^.2 - 5); %defined in the command window`

function [ x ] = falsi(fun,a,b,epsilon) %functions I created

disp(' I a b x'); disp('======= ======= ======= ======');k=0;f(a)=fun(a);f(b)=fun(b);%t=linspace(b,a,100);

%f = fun(t);

%plot(t,f);

%hold on

%set(fig,'color','white')

%grid on

while f(x) > epsilon k=k+1; x = (a*f(b) - b*f(a))/(f(b)-f(a)); f(x)=fun(x); fprintf('%5i,%11.4f;%11.4f,%11.4f\n',k,a,b,x); if f(a)*f(x)< 0 a = x; f(a) = f(x); elseif f(a)*f(x)> 0 b = x; f(b) = f(x); else break end end

## Best Answer