how to use fzero function?
Mostrar comentarios más antiguos
Hello~
I am trying to use fzero function and I am confused about the usage of the function
If I write code like following, it works
syms x
fzero('x.^2-2*x-5',2)
However, if I write code like below, it does not work
syms x
eqn=x.^2-2*x-5;
fzero('eqn', 2) or fzero(eqn,2)
Can anyone tell me the difference between two cases?
thank you
Respuesta aceptada
Más respuestas (1)
David Hill
el 7 de Abr. de 2021
First, fzero finds roots of nonlinear functions and should not be symbolic. If you have a polynomial you should use roots() function. If you have a symbolic use solve() or vpasolve() functions. The documentation for fzero expects a function input that can handle an array of values. The easiest way to satisfy is with an anonymous function as input.
eqn=@(x)x.^2-2*x-5;
fzero(eqn,2);
But for a simple polynomial, better to use roots()
roots([1 -2 -5]);
2 comentarios
Duckyoon Go
el 7 de Abr. de 2021
Walter Roberson
el 8 de Abr. de 2021
fzero() can be useful for polynomials if you want to find a root in a particular range.
... However, it might well be the case that it would be faster to use roots() and filter the results.
Categorías
Más información sobre Symbolic Math Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!