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.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 10일

0 개 추천

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

댓글 수: 1

Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 10일
편집: Azzi Abdelmalek 2012년 11월 10일
also in your program
inline(f)
don't assign anything to f

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

rainbow
rainbow 2012년 11월 10일

0 개 추천

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

카테고리

도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by