Matlab代写:Advanced Math Analysis with Matlab Course Project

Problems and Requirements

Problem 1 (35 points).

Given function

1
F(x, y) = 0.2x^2 + 0.1y^2 + sin(x + y)

please work out its gradient. Based on the gradient, please find out the local extreme of function
F(x,y) when both x and y are in the range of [-2pi, 2pi]. The 2D and 3D views of the
function is given in Fig. 1.

Requirements:

  1. Work out the gradient for F(x, y) and show it in the report;
  2. Write Matlab code to find extreme value for F(x, y) by gradient descent method;
  3. Write a report to show your solution and analysis. Please visualize the gradient
    descent steps along with either its 3D view or the function contour.

Problem 2 (25 points)

A factory supplies engine for its customer. According to the
contract, the factory should deliver its product to the customer in the end of the 1st
season: 40 engines; in the end of the 2nd season: 60 engines; in the end of the 3rd season:
80 engines. Due to limited productivity, to its most, the factory is only able to produce
100 machines in a single season. The production cost is given as f(x) = 50x + 0:2x2,
where x is the number of machines produced in one season. It is possible to produce
machines more than the required quota in each season. In this case, the storage cost is
4 dollars for one machine/season. Assuming there is no reservations at the beginning for
the first season, please work out a production plan that minimizes the production cost.

Requirements:

  1. Model it as a standard quadratic programming problem
  2. Call ‘quadprog’ to solve the problem
  3. Write down the modeling process and show your anwser in the report

image

Sample Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
% Problem1.m

clc
clear all
close all
%%
x = [-2*pi:0.01:2*pi];
y = [-2*pi:0.01:2*pi];
[X,Y] = meshgrid(x,y);
F = 0.2*X.^2+0.1*Y.^2+sin(X+Y);
figure(1)
mesh(X,Y,F);
figure(2)
imagesc(F );
%% Calculate gradient
figure(3)
[Dx,Dy]=gradient(F);
quiver(X,Y,Dx,Dy);
hold on
contour(X,Y,F)
%% Find local maximum and local minimum
lMaxInd = localMaximum(F,[5 5]); % Calculate local maximum
lMinInd = localMaximum(-F,[5 5]);% Calculate local minimum
%% Show extreme point on figure
figure(1)
hold on
shading interp
hold on;
plot3(X(lMaxInd),Y(lMaxInd),F(lMaxInd),'k*','markersize',10,'linewidth',1.5);
hold on
plot3(X(lMinInd),Y(lMinInd),F(lMinInd),'g*','markersize',10','linewidth',1.5);


% Problem2.m
clc
clear all
close all
%%
H = [0.8 0.4;0.4 0.8];
f = [-64 -68];
lb = [40;60];
ub = [100;100];
A = [1 1];
b = 180;
[x,fval,exitflag,output,lambda] = quadprog(H,f,A,b,[],[],lb,ub);
x1 = round(x(1))
x2 = round(x(2))
fmin = 4*(x1-40)+4*(x2-40)+50*x1+0.2*x1^2+50*x2+0.2*x2^2+50*(180-x1-x2)+0.2*(180-x1-x2)^2