Filter löschen
Filter löschen

How do I optimize/find the minimum of a multi-variable function?

17 Ansichten (letzte 30 Tage)
Shayma Al Ali
Shayma Al Ali am 21 Jun. 2024
Bearbeitet: Torsten am 21 Jun. 2024
I'm trying to find the minimum of a multivariable function. I've tried using both fminunc and fminsearch but the results seem incorrect. I'm just confused on what I'm doing wrong and why its not working.
The data:
x=[1.0e-5;1.0e-5;1.0e-5;1.4e-5;1.4e-5;1.4e-5;1.8e-5;1.8e-5;1.8e-5];
y=[1.3e-4;1.55e-4;1.7e-4;1.3e-4;1.55e-4;1.7e-4;1.3e-4;1.55e-4;1.7e-4];
z=[18.488;21.45;24.52;20.93; 26.08; 29.41;25.44;30.98;34.19];
My code:
coeffs=fit([x,y],z,'Poly22');
[~,idx]=min(z);
x(idx)
y(idx)
xval=fminunc(coeffs,[x(idx) y(idx)])
and
A=[x(:).^[0:2] y(:).^[1:2] x(:).*y(:)];
a=A\z(:);
x2=linspace(0,2.00e-5,100);
y2=linspace(0,2.00e-4,100);
[X,Y]=meshgrid(x2,y2);
M=[X(:).^(0:2) Y(:).^(1:2) X(:).*Y(:)];
Z=X;
Z(:)=M*a;
f=@(xy) -14.19 -4.028e+05.*xy(:,1) + 2.774e+05.*xy(:,2)+ 1.473e+10.*xy(:,1).^2 + 7.05e+09.*xy(:,1).*xy(:,2) + -6.256e+08.*xy(:,2).^2;
fminsearch(f,[1.00e-5 1.55e-4])
Both methods give me results that seem incorrect. The fmincon gives me results at:
xval =
1.0e+06 *
0.324231351627941 -1.604585119026901
which based on the data, doesn't make sense at all. What am I doing wrong?

Antworten (1)

Torsten
Torsten am 21 Jun. 2024
Bearbeitet: Torsten am 21 Jun. 2024
If you don't restrict your x- and y- variables to certain lower and upper bounds, the minimum of the function your get from "fit" will be -Inf because the quadratic form you get from poly22 is not positive definite, thus your function not convex:
x=[1.0e-5;1.0e-5;1.0e-5;1.4e-5;1.4e-5;1.4e-5;1.8e-5;1.8e-5;1.8e-5];
y=[1.3e-4;1.55e-4;1.7e-4;1.3e-4;1.55e-4;1.7e-4;1.3e-4;1.55e-4;1.7e-4];
z=[18.488;21.45;24.52;20.93; 26.08; 29.41;25.44;30.98;34.19];
coeffs=fit([x,y],z,'Poly22');
Warning: Equation is badly conditioned. Remove repeated data points or try centering and scaling.
A = [coeffs.p20,coeffs.p11/2;coeffs.p11/2,coeffs.p02];
eig(A)
ans = 2x1
1.0e+10 * -0.0071 2.4067
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Community Treasure Hunt

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

Start Hunting!

Translated by