How do I optimize/find the minimum of a multi-variable function?
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=Az(:);
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?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=Az(:);
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? 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=Az(:);
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? optimization, fminunc, fminsearch, matlab, functions MATLAB Answers — New Questions