Find zero of a polynomial using fzero
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rachel A. Eaglin
am 30 Sep. 2020
Kommentiert: Walter Roberson
am 6 Okt. 2020
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 Kommentar
Walter Roberson
am 6 Okt. 2020
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)
Akzeptierte Antwort
Ameer Hamza
am 30 Sep. 2020
Bearbeitet: Ameer Hamza
am 30 Sep. 2020
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Polynomials 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!