function tent % SETUP THE PROBLEM. % ------------------------------------------------- n = 30; mu = 2; % Define positions and heights of the poles: x1 = [0.25;0.25]; p1 = 1; x2 = [0.25;0.75]; p2 = 1; x3 = [0.75;0.25]; p3 = 1; x4 = [0.75;0.75]; p4 = 1; x5 = [0.50;0.50]; p5 = 1.5; % constraint function definition function res = constraint(x); r = [0.03;0.03]; res = 0; if all(abs( x - x1 ) < r), res = p1; end if all(abs( x - x2 ) < r), res = p2; end if all(abs( x - x3 ) < r), res = p3; end if all(abs( x - x4 ) < r), res = p4; end if all(abs( x - x5 ) < r), res = p5; end end % set up the grid with (n+2) x (n+2) points [xfull,yfull] = meshgrid( linspace(0,1,n+2) ); hh = 1/(n+1); % only the inner points are degrees of freedom x = xfull(2:end-1,2:end-1); y = yfull(2:end-1,2:end-1); % discretize the constraint function on the grid z = zeros(size(x)); for i = 1:length(x(:)) z(i) = constraint( [x(i);y(i)] ); end % PREPARE ACTIVE SET ALGORITHM. % ------------------------------------------------- % Define the arguments for the active set algorithm G = % h = % TODO: A = % ADD HERE THE CORRECT ARGUMENTS FOR THE b = % ACTIVE SET METHOD AS DEFINED ON THE C = % EXERCISE SHEET d = % x0 = ones( n*n, 1); % initial starting guess % SOLVE. % ------------------------------------------------- xstar = activeset( G, h, A, b, C, d, x0 ); xstar = reshape( xstar, n, n ); % PLOT % ------------------------------------------------- % plot the constraint function. % (include the boundary points again) zfull = zeros(size(xfull)); zfull(2:end-1,2:end-1) = z; figure(1) surfl( xfull, yfull, zfull ) xlabel('x') ylabel('y') zlabel('g(x,y)') set(gca,'fontsize',16) colormap(gray) view([-20,30]); % plot the solution. % (include the boundary points again) xstarfull = zeros(size(xfull)); xstarfull(2:end-1,2:end-1) = xstar; figure(2) surfl( xfull, yfull, xstarfull ) xlabel('x') ylabel('y') zlabel('u(x,y)') set(gca,'fontsize',16) colormap(gray) view([-20,30]); end