MATLAB: Matlab function defining problem

function definingMATLAB

hi everybody!
I want to ask how to define a function in MATLAB. For example,part of the code is like that:
function program1(xl,xu,es,imax,xr,n,ea)
n=0;
f=input('Enter the function f:','s');
inline(f)
ezplot(f)
xl=input('Seeing the graph,decide on the first initial guess:');
xu=input('The upper initial guess:');
fl=f(xl);
fu=f(xu);
tol = input('Enter tol ');
ea = 1e8;
iu = 0;
il = 0;
xr_old = 0;
n = 0;
while ea > tol
n = n+1;
xr = xu - fu*(xl-xu)/(fl-fu);
fr = f(xr);
ea=100*abs((xr-xr_old)/xr);
if fu*fr < 0;
xl= xr;
fl = fr;
il = 0;
iu = iu+1;
.....................
I cannot define the function f of x, so , i guess the program takes my x s as index and gives me
Attempted to access f(0); index must be a positive integer or logical.
Error in program1 (line 10)
fl=f(xl);
So, how can I fix this?
Thank you in advance.

Best Answer

When you enter a function f you should enter for example for sine function
@sin