Find zero of a polynomial using fzero

조회 수: 12 (최근 30일)
Rachel A. Eaglin
Rachel A. Eaglin 2020년 9월 30일
댓글: Walter Roberson 2020년 10월 6일
I am trying to find the zeros of deflecPrime using fzero (not roots).
deflecPrime=(w/(48*E*I)).*[8 -15*L 6*L^2 0];
%zero of deflection derivative
fun=@deflecPrime;
x0=L/2;
maxDeflec=fzero(fun,x0)
I keep getting this error:
FZERO cannot continue because user-supplied function_handle ==> deflecPrime failed with the
error below.
Undefined function 'deflecPrime' for input arguments of type 'double'.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 10월 6일
By the way, with respect to your recent question that you deleted:
[X,Y]=meshgrid(x,y);
X and Y will both be 2D arrays.
f=2.25*X.*Y+1.75*Y-1.5*X.^2-2*Y.^2;
f is built from 2D arrays, so f will be a 2D array.
fun = @(z)-2.25*X.*Y-1.75*Y+1.5*X.^2+2*Y.^2;
You accept an input but ignore it and always return the same thing that was calculated and stored into f.
You could change the @(z) to @(f) but that would not make any difference.
z = fminsearch(fun,x0)
the function you pass to fminsearch must return a scalar, not an array.
I suspect what you want is
fun = @(XY)-2.25*XY(1).*XY(2)-1.75*XY(2)+1.5*XY(1).^2+2*XY(2).^2;
Note, by the way, that you can calculate the optimum using calculus instead of fminsearch. When f is of the form
A*X.*Y + B*Y - C*X.^2 - D*Y.^2
then
x = -(A*B)/(A^2 - 4*C*D)
y = -(2*B*C)/(A^2 - 4*C*D)
is the critical location. (Caution: you really should check whether it is a minima or maxima)

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 9월 30일
편집: Ameer Hamza 2020년 9월 30일
You need to define deflecPrime as a function handle
deflecPrime = @(L) sum((w/(48*E*I)).*[8 -15*L 6*L^2 0]); % sum all the terms too
and then call fzero like this
fun = deflecPrime;
x0=L/2;
maxDeflec=fzero(fun,x0)
However, fzero will not give al the roots. For that, use roots(): https://www.mathworks.com/help/matlab/ref/roots.html.
deflecPrime = (w/(48*E*I)).*[6 -15 8] % [cofficients of x^2, x, 1]
roots(deflecPrime)
  댓글 수: 3
Rachel A. Eaglin
Rachel A. Eaglin 2020년 9월 30일
Got it! Thank you!
Ameer Hamza
Ameer Hamza 2020년 9월 30일
I am glad to be of help!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by