error: fzero: zero point is not bracketed

9 visualizaciones (últimos 30 días)
Andreea Oana
Andreea Oana el 5 de En. de 2022
Comentada: Star Strider el 5 de En. de 2022
Hi. So this is what I wrote so far in octave:
syms x
f=4*x.^2+20*x+4
f = 
x=fzero(@(x) f, -5)
Error using fzero (line 308)
Initial function value must be finite and real.
but I keep getting the error in the title. What is wrong with what I wrote? Thanks in advance!

Respuestas (1)

Star Strider
Star Strider el 5 de En. de 2022
Use fzero for numeric functions and solve for symbollic functions —
syms x
f=4*x.^2+20*x+4
f = 
x=vpa(solve(f==0))
x = 
format long
xd = double(x)
xd = 2×1
-4.791287847477920 -0.208712152522080
whos x xd
Name Size Bytes Class Attributes x 2x1 8 sym xd 2x1 16 double
.
  3 comentarios
Walter Roberson
Walter Roberson el 5 de En. de 2022
syms x
f=4*x.^2+20*x+4
f = 
F = matlabFunction(f)
F = function_handle with value:
@(x)x.*2.0e+1+x.^2.*4.0+4.0
x = fzero(F, -5)
x = -4.7913
or
f = @(x) 4*x.^2 + 20*x + 4
f = function_handle with value:
@(x)4*x.^2+20*x+4
x = fzero(f, -5)
x = -4.7913
Star Strider
Star Strider el 5 de En. de 2022
One approach —
syms x
f=4*x.^2+20*x+4
f = 
f_fcn = matlabFunction(f)
f_fcn = function_handle with value:
@(x)x.*2.0e+1+x.^2.*4.0+4.0
format long
x=fzero(f_fcn,-5)
x =
-4.791287847477920
To get the other root, use a different initial parameter estimate —
x=fzero(f_fcn,-1)
x =
-0.208712152522080
See the documentation on matlabFunction for details.
.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by