Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Big Data Interview 751 Comprehensive Questions And Expert Answers

Authors: Mr Bhanu Pratap Mahato

1st Edition

B0CLNT3NVD, 979-8865047216

More Books

Students also viewed these Databases questions