# # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # # EPage # #----- # Ex. 1 Part (a): # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_1_part_a.eps", onefile=FALSE, horizontal=FALSE) x_1 = seq( -4, +6, length=100 ) x_2 = -2 * x_1 / 3 plot( x_1, x_2, type='l' ) text( -3, 1, '-2 x_1 - 3 x_2 <= 0' ) abline( v=3 ) abline( h=2 ) x = c( 3, 3, -3 ) y = c( -2, 2, 2 ) polygon( x, y, col="gray" ) grid() #dev.off() # Ex. 1 Part (b): # # Solve each pair of equations: # # solve equations 1 & 2: a = matrix( data=c(-2,-3,-1,+1), nrow=2, ncol=2, byrow=TRUE ) b = matrix( data=c(-6,+2), nrow=2, ncol=1 ) rt_1 = solve( a, b ) # (0,2) # solve equations 1 & 3: a = matrix( data=c(-2,-3,+1,+1), nrow=2, ncol=2, byrow=TRUE ) b = matrix( data=c(-6,+3), nrow=2, ncol=1 ) rt_2 = solve( a, b ) # (3,0) # solve equations 2 & 3: a = matrix( data=c(-1,+1,+1,+1), nrow=2, ncol=2, byrow=TRUE ) b = matrix( data=c(+2,+3), nrow=2, ncol=1 ) rt_3 = solve( a, b ) # (0.5,2.5) # Plot the enclosing polygon: # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_1_part_b.eps", onefile=FALSE, horizontal=FALSE) #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_1_part_c.eps", onefile=FALSE, horizontal=FALSE) x_1 = seq( -4, +6, length=100 ) x_2 = 2 - ( 2/3 ) * x_1 plot( x_1, x_2, type='l' ) text( -3, 3, '-2 x_1 - 3 x_2 <= -6' ) #polygon( c(6,6,-4), c(-2,14/3,14/3), col=NA, border="green" ) #polygon( c(8/3,6,6,-4), c(14/3,14/3,-2,-2), col=NA, border="red" ) x_2 = 2 + x_1 lines( x_1, x_2 ) text( 4, 4, '- x_1 + x_2 <= 2' ) x_2 = 3 - x_1 lines( x_1, x_2 ) M = matrix( data=c( rt_1, rt_2, rt_3 ), nrow=2, ncol=3, byrow=F ) xs = M[1,] ys = M[2,] polygon( xs, ys, col="gray" ) grid() #dev.off() # Ex. 1 Part (c): The same system of equations as in Part (b) just with a different polygonal region # # polygon( c(-4,0,3,5), c(-2,2,0,-2), col="gray" ) # Ex. 1 Part (d): # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_1_part_d.eps", onefile=FALSE, horizontal=FALSE) x_1 = seq( 0, +4, length=100 ) x_2 = rep(0,length(x_1)) plot(x_1,x_2,ylim=c(-1,4),type='l') abline(v=0) abline(v=2) polygon( c(0,2,2,0), c(0,0,4,4), col="gray" ) grid() #dev.off() # Ex. 1 Part (e): # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_1_part_e.eps", onefile=FALSE, horizontal=FALSE) x_1 = seq( -3, +3, length=100 ) x_2 = rep(0, length(x_1) ) plot(x_1,x_2,ylim=c(-4,+4),type='l') polygon( c(+2,+2,-2,-2), c(-3,+3,+3,-3), col="gray" ) grid() #dev.off() # Ex. 1 Part (f): # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_1_part_f.eps", onefile=FALSE, horizontal=FALSE) x_1 = seq( -4, +4, length=100 ) x_2 = ( -6 - 3 * x_1 ) / 2 plot(x_1,x_2,ylim=c(-4,+4),type='l') x_2 = ( +6 - 3 * x_1 ) / 2 lines(x_1,x_2,ylim=c(-4,+4),type='l') polygon( c(+2/3,-4,-4), c(-4,+3,-4), col="gray" ) grid() #dev.off() # Ex. 1 Part (h): # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_1_part_h.eps", onefile=FALSE, horizontal=FALSE) x_1 = seq( -4, +4, length=100 ) x_2 = x_1 plot(x_1,x_2,ylim=c(-4,+4),type='l') x_2 = -x_1 lines(x_1,x_2,ylim=c(-4,+4),type='l') polygon( c(+4,0,-4), c(-4,0,-4), col="gray" ) grid() #dev.off() # Ex. 1 Part (i): # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_1_part_i.eps", onefile=FALSE, horizontal=FALSE) x_1 = seq( -2, +7, length=100 ) x_2 = rep( 0, length(x_1) ) plot(x_1,x_2,ylim=c(-4,+4),type='l') abline(v=2) abline(v=5) polygon( c(+2,+2,-2,-2), c(-4,+4,+4,-4), col="gray" ) polygon( c(+5,+7,+7,+5), c(-4,-4,+4,+4), col="gray" ) grid() #dev.off() # Ex. 1 Part (j): # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_1_part_j.eps", onefile=FALSE, horizontal=FALSE) x_1 = seq( -2, +6, length=100 ) x_2 = ( -6 + 3 * x_1 ) / ( -2 ) plot(x_1,x_2,ylim=c(-2,+6),type='l') x_2 = ( -6 + 2 * x_1 ) / ( -3 ) lines(x_1,x_2,type='l') polygon( c(0,0,6/5,3,6,6), c(+6,+3,6/5,0,0,6), col="gray" ) grid() #dev.off() # Ex. 2 # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_2.eps", onefile=FALSE, horizontal=FALSE) x_1 = seq( -1, +40, length=100 ) x_2 = ( 60 - 2 * x_1 ) / 3 plot(x_1,x_2,ylim=c(-1,+30),type='l') lines(x_1,x_1,type='l') polygon( c(0,30,12), c(0,0,12), col="gray" ) grid() #dev.off() #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_2_second_part.eps", onefile=FALSE, horizontal=FALSE) x_1 = seq( -1, +40, length=100 ) x_2 = ( 60 - 2 * x_1 ) / 3 plot(x_1,x_2,ylim=c(-1,+30),type='l') lines(x_1,x_1,type='l') abline(v=20) abline(h=0) abline(v=0) #polygon( c(20,30,20), c(0,0,20/3), col="gray" ) # region for x_1 > 20 polygon( c(0,20,20,12), c(0,0,20/3,12), col="gray" ) # region for x_1 < 20 grid() #dev.off() # Ex. 7 # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_7.eps", onefile=FALSE, horizontal=FALSE) X = seq( -10, +600, length=100 ) Y = ( 2400 - 4 * X ) / 3 plot(X,Y,type='l') abline(h=0) abline(v=0) abline(h=600) polygon( c(0,600,150,0), c(0,0,600,600), col="gray" ) grid() #dev.off() # Ex. 9 # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_9.eps", onefile=FALSE, horizontal=FALSE) X = seq( -10, +600, length=100 ) Y = ( 2400 - 4 * X ) / 3 plot(X,Y,type='l') abline(h=0) abline(v=0) abline(h=600) Y = 1.5*X points(X,Y,type='l') x_intersection = 282.3529 polygon( c(0,600,x_intersection), c(0,0,1.5*x_intersection), col="gray" ) grid() #dev.off() # Ex. 10 # #postscript("../../WriteUp/Graphics/Chapter7/section_1_prob_10.eps", onefile=FALSE, horizontal=FALSE) w_1 = seq( -1, +6, length=100 ) w_2 = ( 40 - 80 * w_1 ) / 15 plot(w_1,w_2,type='l',ylim=c(-2.5,+10)) abline(h=0) abline(v=0) w_2 = ( 30 - 10 * w_1 ) / 60 points(w_1,w_2,type='l') x_intersection = 13/31 y_intersection = ( 30 - 10 * x_intersection ) / 60 polygon( c(0,0,x_intersection,3,6,6), c(10,8/3,y_intersection,0,0,10), col="gray" ) grid() #dev.off()