Matlab function defining problem
Ältere Kommentare anzeigen
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 Kommentar
Azzi Abdelmalek
am 10 Nov. 2012
what is f?
Akzeptierte Antwort
Weitere Antworten (1)
rainbow
am 10 Nov. 2012
0 Stimmen
Kategorien
Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!