how to use function in fzero as a variable file

Hello,
There's a simple example of fzero here, that defines a function in a file called f.m: https://www.mathworks.com/help/matlab/ref/fzero.html
What I need, is that f.m to be a variable passed into the calling function, because it can be from any file (f.m, f1.m, etc). Matlab complains if i try to pass in f through arguments because it's already used as a function. Is there a trick to it?
Thanks so much,
Dave

 채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 9일

0 개 추천

Look at this other example instead:
fun = @f; % function
x0 = 2; % initial point
z = fzero(fun,x0)
and if you wanted f1.m then you would use
fun = @f1

댓글 수: 3

But I want to always refer in my main code to @f, where f is the name of a file that is passed in through arguments. Then I don't have to hard code now an @f1 in the main code...
str2func
I got that to work. Thank you.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

태그

질문:

2016년 10월 9일

댓글:

2016년 10월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by