Question: Hi, I am having trouble with this MatLab code which i have pasted below. The code is supposed to find the optimum(s) of the function

Hi, I am having trouble with this MatLab code which i have pasted below. The code is supposed to find the optimum(s) of the function using the gradient method. We were provided this initial program and are supposed to make corrections to the lines that say " %FIX ME! ", but I am stuck. Any help would be greatly appreciated, thank you

%Implementing gradient method to find optimum

syms x y

%define function and 1st derivative;

f(x,y) = -8*x+x^2 +12*y+4*y^2-2*x*y;

d_fx = subs(diff(f, x));

d_fy = subs(diff(f, y));

%initial value of x0, y0;

x0 = 0;

y0 = 0;

%iterate for 10 times;

for i=1:10

syms h

%compute df/dx df/dy in (x0, y0);

fx_1 = double(d_fx(x0,y0));

fy_1 = double(d_fy(x0,y0));

%compute x1, y1 with h;

%FIX ME!

x1 = ;

y1 = ;

%compute h;

% FIX ME!

%update x, y;

% FIX ME!

end

fprintf('the optimum: x=%i ',x0);

fprintf('the optimum: y=%i ',y0);

z = subs(f);

z0 = double(z(x0,y0));

%%

%plot in 3D

x = -100:0.001:100;

y = -100:0.001:100;

z = -8*x+x.^2 +12*y+4*y.^2-2*x.*y;

figure

plot3(x,y,z)

% hold on

% %plot the optimum

% plot3(x0,y0,z0,'*')

% hold off

grid on

xlabel('x');

ylabel('y');

zlabel('f(x,y)');

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!