Quotes around the name of the function
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 ...
0 Kommentare
Akzeptierte Antwort
Matt Fig
am 15 Dez. 2012
Bearbeitet: Matt Fig
am 15 Dez. 2012
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 Kommentare
Matt Fig
am 15 Dez. 2012
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....
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!