Matlab function defining problem

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.

 Risposta accettata

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

1 Commento

Azzi Abdelmalek
Azzi Abdelmalek il 10 Nov 2012
Modificato: Azzi Abdelmalek il 10 Nov 2012
also in your program
inline(f)
don't assign anything to f

Accedi per commentare.

Più risposte (1)

rainbow
rainbow il 10 Nov 2012

0 voti

thank you thank you thank you so muchhhh!!!!!

Categorie

Scopri di più su MATLAB in Centro assistenza e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by