error: fzero: zero point is not bracketed

9 Ansichten (letzte 30 Tage)
Andreea Oana
Andreea Oana am 5 Jan. 2022
Kommentiert: Star Strider am 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!

Antworten (1)

Star Strider
Star Strider am 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 Kommentare
Walter Roberson
Walter Roberson am 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 am 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.
.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by