Problem
Find minimum of x^2 + 4y^2 -3xy -3x -7y
Subject to 0<x<7 0<y<7
Change constraints till you hit both
Matlab Solution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Programme : EngD Maths for Systems % Date : 2011-06-01 % Session : Optimisation % Exercise : Material Blending % By : Richard Craig % % Description: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% quadprog4.m %Find minimum of x^2 + 4y^2 -3xy -3x -7y %Subject to 0<x<7 0<y<7 clc; clear; %% Set up function for optimization % H will give expression of form: % h11.x1^2 +h12.x1.x2 +h21.x2.x1 +h22.x2^2 % but programme forces symmetric Hessian: h12=h21 etc., % so might as well make it symmetric now. % from the eq we can see H = [x^2 + 4y^2 -3xy] f = [ -3x -7y] H = [2 -3; -3 8]; %H = [x^2 + 4y^2 -3xy] % f will give inner product f.x f = [-3; -7]; % f = [ -3x -7y] %% Constraints %x = quadprog(H,f,A,b,Aeq,beq) solves the preceding problem while %additionally satisfying the equality constraints Aeq*x = beq. %If no inequalities exist, set A = [] and b = []. A = [];b = []; %lower bounds on x: lb = zeros(2,1); %upper bound on x: ub = [16 7]; %[7 7]; %Subject to 0<x<7 0<y<7 %% View Function % make a "meshgrid" to cover allowed ranges of the variables. u=linspace(lb(1),ub(1),11); v=linspace(lb(2),ub(2),11); [X, Y]=meshgrid(u,v); % put a value to each point-pair of the grid: Z=0.5*(H(1,1)*X.^2 + H(2,2)*Y.^2 + 2*H(1,2).*X.*Y) + f(1).*X + f(2).*Y; %plot the surface with some colour and a contour plot underneath: h = figure(1); surfc(X,Y,Z) saveas(h,'QuadSurface.jpg'); %% Minimize using 'quadprog' % Call for quadratic programming method: [x,fval] = quadprog(H,f,A,b,[],[],lb,ub)
Similar Code Posts
Business Rules of Play
While reading about Peter R. Scholtes, I came across the Kelly Allen Associates website and their listed ‘Rules of Play’ page. Many of the rules of business are simple and obvious, yet are easy to overlook or break.
Potential scale for EngD stakeholders
I’ve been thinking about a nice, quick and easy scale to base value decisions against a (potential) stakeholder’s relationship to the research project.
Lean Working
I’m sure I’m not the only one who sometimes gets overloaded with work to be done. It can feel like waves of stress to get things done, trying to progress multiple jobs that just seem to hang around. After reading some more on LEAN principles again recently, I thought I’d give the LEAN approach to [...]
