Matlab function defining problem
Afficher commentaires plus anciens
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.
1 commentaire
Azzi Abdelmalek
le 10 Nov 2012
what is f?
Réponse acceptée
Plus de réponses (1)
rainbow
le 10 Nov 2012
0 votes
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!