% % Written by: % -- % John L. Weatherwax 2008-06-11 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- clc; close all; % consider the different possible values of x_P x_P = -1 + [ +1, -1 ]*(1/sqrt(2)) x_P = x_P(1); % consider the different possible values of x_Q x_Q = +1 + [ +1, -1 ]*(1/sqrt(2)) x_Q = x_Q(2); all_x = linspace(-1,+1); % get the coefficients of the linear function to the left: B = -2*x_P; A = B; % get the coefficients of the linear function to the right: D = -2*x_Q; C = -D; indL = find( all_x <= x_P ); indM = find( (all_x > x_P) & (all_x < x_Q) ); indR = find( all_x >= x_Q ); % map each region into its functional representation: obs_y = zeros(1,length(all_x)); obs_y(indL) = A+B*all_x(indL); obs_y(indM) = 0.5 - all_x(indM).^2; obs_y(indR) = C+D*all_x(indR); figure; sh=plot( all_x, obs_y, '-k' ); hold on; grid on; oh=plot( all_x, 0.5-all_x.^2, '-go' ); axis( [-1,+1,0,Inf] ); legend([sh,oh],{'obstacle solution','obstacle'},'location','south'); xlabel('x-axis'); ylabel('u(x)'); title( 'obstacle solution' ); saveas( gcf, '../../WriteUp/Graphics/Chapter7/prob_7_3_pt_a', 'epsc' );