# Quotes around the name of the function

조회 수: 5 (최근 30일)
Antonis V. 2012년 12월 15일
When do we put quotes around the name of the function and when not ? For example, I used fsolve(myfun,x0) and I got no results , but when I used fsolve('myfun',x0) I got the root I was looking for ...

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

### 채택된 답변

Matt Fig 2012년 12월 15일
편집: Matt Fig 2012년 12월 15일
Typically, you want to pass a handle to a function, not a string.
fsovle(@myfun,x0) % Notice the @ symbol --> a function handle.
The string argument gets evaluated the same way, probably for backward compatibility. The modern way is to use function handles.
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
Matt Fig 2012년 12월 15일
You would have to show exactly what you did in order for me to know why one code failed.
f = @(x) exp(x) - cos(x) - 1; % f is a function handle.
fsolve(f,0) % Seems to work....
f = @(x) exp(x) - x^2 - 68 ; % Another function handle.
fsolve(f,0) % Also works....
Antonis V. 2012년 12월 15일
Ok i found out why it failed ! I had created and saved this function so I guess I had to use fsolve(@f,0) in first place ! Thanks a lot ! And one last thing :P I am a new Matlab user , and I haven't yet figured out how initial guesses work !For instance, I want to find out the roots of the equation F(X) = exp(x) - x^2 - 68 . What values should I put to x0 ? I 've tried several values close to 0 and I got the same result but I noticed I can't use very big numbers , whereas I can use very small numbers. If I want to find all the roots at F's domain range should I put more than one values at x0 ?

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

### 카테고리

Help CenterFile Exchange에서 Common Operations에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by