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 Center および File ExchangePolynomials についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by