Why does version R2020b gives errors when running functions such as fmincon, when version R2019a runs properly.
Show older comments
This is the code I'm running:
clear;clc
syms x y z
f=8*x.^2+y.^3;
c=5-x-y;
L=f-z*c;
dL_dx=matlabFunction(diff(L,x),'Vars',[x,y,z]);
dL_dy=matlabFunction(diff(L,y),'Vars',[x,y,z]);
dL_dz=matlabFunction(diff(L,z),'Vars',[x,y,z]);
d2L_dx2=matlabFunction(diff(dL_dx,x),'Vars',[x,y,z]);
d2L_dxy=matlabFunction(diff(dL_dx,y),'Vars',[x,y,z]);
d2L_dxz=matlabFunction(diff(dL_dx,z),'Vars',[x,y,z]);
d2L_dyx=matlabFunction(diff(dL_dy,x),'Vars',[x,y,z]);
d2L_dy2=matlabFunction(diff(dL_dy,y),'Vars',[x,y,z]);
d2L_dyz=matlabFunction(diff(dL_dy,z),'Vars',[x,y,z]);
d2L_dzx=matlabFunction(diff(dL_dz,x),'Vars',[x,y,z]);
d2L_dzy=matlabFunction(diff(dL_dz,y),'Vars',[x,y,z]);
d2L_dz2=matlabFunction(diff(dL_dz,z),'Vars',[x,y,z]);
max_iterations=100;
x_search=zeros(1,max_iterations);
y_search=zeros(1,max_iterations);
z_search=zeros(1,max_iterations);
x_search(1)=2;
y_search(1)=2;
z_search(1)=0;
for n=1:max_iterations
h11=d2L_dx2(x_search(n),y_search(n),z_search(n));
h12=d2L_dxy(x_search(n),y_search(n),z_search(n));
h13=d2L_dxz(x_search(n),y_search(n),z_search(n));
h21=d2L_dyx(x_search(n),y_search(n),z_search(n));
h22=d2L_dy2(x_search(n),y_search(n),z_search(n));
h23=d2L_dyz(x_search(n),y_search(n),z_search(n));
h31=d2L_dzx(x_search(n),y_search(n),z_search(n));
h32=d2L_dzy(x_search(n),y_search(n),z_search(n));
h33=d2L_dz2(x_search(n),y_search(n),z_search(n));
H=[h11,h12,h13;...
h21,h22,h23;...
h31,h32,h33];
grad=[dL_dx(x_search(n),y_search(n),z_search(n));...
dL_dy(x_search(n),y_search(n),z_search(n));...
dL_dz(x_search(n),y_search(n),z_search(n))];
temp=[x_search(n);y_search(n);z_search(n)]-H^-1*grad;
x_search(n+1)=temp(1);
y_search(n+1)=temp(2);
z_search(n+1)=temp(3);
end
clear L
L=@(x) 8*x(1)^2+x(2)^3;
x0=[x_search(1);y_search(1)];
A=[];
b=[];
Aeq=[1 1];
beq=5;
xmin=fmincon(L,x0,A,b,Aeq,beq);
[x1,x2]=meshgrid(-4:0.01:4);
z=8*x1.^2+x2.^3;
figure;hold on
mesh(x1,x2,z)
plot(-4:0.01:4,5-(-4:0.01:4),'r')
xlabel('x1');ylabel('x2');zlabel('f')
figure;hold on
contour(x1,x2,z,20)
plot(-4:0.01:4,5-(-4:0.01:4),'r')
plot(x_search,y_search,'g')
xlabel('x1');ylabel('x2');zlabel('f')
grid
When I run it at school on version R2019a everything works. When I run it at home on version R2020b I get the following error message:
Unrecognized function or variable 'getIpOptions'.
Error in fmincon (line 846)
options = getIpOptions(options,sizes.nVar,mEq,flags.constr,defaultopt,10,0.01);
Error in example_2 (line 66)
xmin=fmincon(L,x0,A,b,Aeq,beq);
Accepted Answer
More Answers (0)
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!