error: fzero: zero point is not bracketed

2 views (last 30 days)
Andreea Oana
Andreea Oana on 5 Jan 2022
Commented: Star Strider on 5 Jan 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!

Answers (1)

Star Strider
Star Strider on 5 Jan 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 Comments
Walter Roberson
Walter Roberson on 5 Jan 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 on 5 Jan 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.
.

Sign in to comment.

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!