error: fzero: zero point is not bracketed

조회 수: 9 (최근 30일)
Andreea Oana
Andreea Oana 2022년 1월 5일
댓글: Star Strider 2022년 1월 5일
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!

답변 (1개)

Star Strider
Star Strider 2022년 1월 5일
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
Walter Roberson
Walter Roberson 2022년 1월 5일
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 2022년 1월 5일
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.
.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by