clear all, close all syms x1 x2 z=x1*(10+31*x1^(-0.5)+1.3*x2^(-0.2))-18*x1+... x2*(5+15*x2^(-0.4)+.8*x1^(-0.08))-10*x2; ezsurfc(z, [0.1 10 0.1 10]); title('Objective Function z'); x=[x1;x2]; F=diff(z,x1); G=diff(z,x2); Dz=[F;G]; % the gradient vector of z
Finds approximate solution of Dz=0 starting with an initial guess.
First, find the derivative of Dz=[F;G]
dFdx1=diff(F,x1); dFdx2=diff(F,x2);
dGdx1=diff(G,x1); dGdx2=diff(G,x2);
D2z =[dFdx1 dFdx2; dGdx1 dGdx2]; % Jacobian of Dz (same as Hessian of D2z)
x0=[5;5]; % initial guess N=10; % number of iterations for i=1:N Dz0=subs(Dz,[x1,x2],[x0(1),x0(2)]); D2z0=subs(D2z,[x1,x2],[x0(1),x0(2)]); xnew=x0-inv(D2z0)*Dz0; x0=xnew; end xmax = xnew; zmax = subs(z,[x1,x2], [xmax(1),xmax(2)]);
The optimal choice for (x1,x2) seems to be
x0 figure, ezcontourf(z,[0.1 10 0.1 10]) hold on plot3(xmax(1),xmax(2),zmax, 'mo',... 'LineWidth',2,... 'MarkerEdgeColor','k',... 'MarkerFaceColor',[.49 1 .63],... 'MarkerSize',12); title('Countour plot and optimal value');
x0 = 4.6896 5.8520
and the maximum objective value is
zmax
zmax = 52.0727