Why does version R2020b gives errors when running functions such as fmincon, when version R2019a runs properly.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Vitas Diktanas
el 13 de Abr. de 2021
Comentada: Bjorn Gustavsson
el 14 de Abr. de 2021
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);
0 comentarios
Respuesta aceptada
Bjorn Gustavsson
el 13 de Abr. de 2021
Have you installed the optimization toolbox in your 2020b install? If not that is where that function resides.
Check the existence of functions with the which command:
which getIpOptions -all
HTH
2 comentarios
Bjorn Gustavsson
el 14 de Abr. de 2021
Good!
(The general advice (perhaps?) is to install everything you have the license for. If collaborating with someone that has access to a smaller number of toolboxes it is sometimes tricky to not include handy functions from some "too specialised" toolbox...)
Más respuestas (0)
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!