# # 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. # #----- save_plots = F # Chapter 7: Section 3: Exercise 3 # x = seq( from=-50, to=800, length.out=100 ) y = ( 2100 - 6 * x ) / 5 if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_3_prob_3.eps", onefile=FALSE, horizontal=FALSE) } plot( x, y, type='l', xlim=c(-50,+600), ylim=c(-50,450) ) y = ( 2100 - 3 * x ) / 6 lines( x, y, type='l', col='blue' ) abline( h=0 ) abline( v=0 ) polygon( c(0,350,100,0), c(0,0,300,350), col='gray' ) grid() if( save_plots ){ dev.off() } # Chapter 7: Section 3: Exercise 4 # x = seq( from=-0.5, to=2.0, length.out=100 ) y = ( 0.12 - 0.15 * x ) / 0.1 if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_3_prob_4.eps", onefile=FALSE, horizontal=FALSE) } plot( x, y, type='l', xlab='v_1', ylab='v_2', xlim=c(-0.25,+2), ylim=c(-0.25,+2) ) y = ( 2 - 1.67 * x ) / 3.33 lines( x, y, type='l', col='blue' ) abline( h=0 ) abline( v=0 ) polygon( c(0,0,0.6,1.197,3,3), c(3,1.2,0.3,0,0,3), col='gray' ) grid() if( save_plots ){ dev.off() } # Chapter 7: Section 3: Exercise 6 # x = seq( from=-100, to=400, length.out=100 ) y = 200 - x if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_3_prob_6.eps", onefile=FALSE, horizontal=FALSE) } plot( x, y, type='l', xlab='x_1', ylab='x_2', xlim=c(-50,+400), ylim=c(-50,300) ) y = ( 320 - x ) / 4 lines( x, y, type='l', col='blue' ) y = ( 2200 - 10*x ) / 20 lines( x, y, type='l', col='red' ) abline( h=0 ) abline( v=0 ) polygon( c(0,200,180,120,0), c(0,0,20,50,80), col='gray' ) grid() if( save_plots ){ dev.off() } print( "Chapter 7: Section 3: Exercise 7" ) # x = seq( from=-1, to=20, length.out=100 ) y = ( 8 - x ) / 3 if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_3_prob_7.eps", onefile=FALSE, horizontal=FALSE) } plot( x, y, type='l', xlim=c(-1,+15), ylim=c(-0.25,10) ) y = ( 19 - 3 * x ) / 4 lines( x, y, type='l', col='blue' ) y = 7 - 12 * x lines( x, y, type='l', col='red' ) abline( h=0 ) abline( v=0 ) # The intersection of the red and blue lines: A = matrix( data=c(3,4,12,1), nrow=2, ncol=2, byrow=T ) b = matrix( data=c(19,7), nrow=2 ) s_rb = solve( A, b ) print( s_rb ) # The intersection of the blue and black lines: A = matrix( data=c(3,4,1,3), nrow=2, ncol=2, byrow=T ) b = matrix( data=c(19,8), nrow=2 ) s_bb = solve( A, b ) print( s_bb ) x_extreme = c(0,0,s_rb[1],s_bb[1],8,20,20) y_extreme = c(20,7,s_rb[2],s_bb[2],0,0,20) polygon( x_extreme, y_extreme, col='gray' ) grid() if( save_plots ){ dev.off() } for( ii in 2:(length(x_extreme)-2) ){ x = x_extreme[ii] y = y_extreme[ii] print( sprintf( "(%10.5f, %10.5f) has cost %10.6f", x_extreme[ii], y_extreme[ii], x + 0.25*y ) ) } print( "Chapter 7: Section 3: Exercise 8" ) # x = seq( from=-1, to=20, length.out=100 ) y = ( 8 - x ) / 3 if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_3_prob_8.eps", onefile=FALSE, horizontal=FALSE) } plot( x, y, type='l', xlim=c(-1,+15), ylim=c(-0.25,6), xlab='v_1', ylab='v_2' ) y = ( 19 - 3 * x ) / 4 lines( x, y, type='l', col='blue' ) y = 7 - 12 * x lines( x, y, type='l', col='red' ) abline( h=0 ) abline( v=0 ) abline( v=0.5, col='green' ) # The intersection of the green and blue lines: s_gb = c(0.5,17.5/4) # The intersection of the blue and black lines: A = matrix( data=c(3,4,1,3), nrow=2, ncol=2, byrow=T ) b = matrix( data=c(19,8), nrow=2 ) s_bb = solve( A, b ) x_extreme = c(0 ,s_gb[1],s_bb[1],8,20,20) y_extreme = c(20,s_gb[2],s_bb[2],0, 0,20) polygon( x_extreme, y_extreme, col='gray' ) grid() if( save_plots ){ dev.off() } for( ii in 2:(length(x_extreme)-2) ){ x = x_extreme[ii] y = y_extreme[ii] print( sprintf( "(%10.5f, %10.5f) has cost %10.6f", x_extreme[ii], y_extreme[ii], x + 0.25*y ) ) } print( "Chapter 7: Section 3: Exercise 9" ) # x = seq( from=-1, to=20, length.out=100 ) y = ( 8 - x ) / 3 if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_3_prob_9.eps", onefile=FALSE, horizontal=FALSE) } plot( x, y, type='l', xlim=c(-1,+15), ylim=c(-0.25,6), xlab='v_1', ylab='v_2' ) y = ( 19 - 3 * x ) / 4 lines( x, y, type='l', col='blue' ) y = 7 - 12 * x lines( x, y, type='l', col='red' ) abline( h=0 ) abline( v=0 ) abline( h=2, col='green' ) # The intersection of the green and blue lines: s_gb = c(11/3,2) # The intersection of the blue and black lines: A = matrix( data=c(3,4,1,3), nrow=2, ncol=2, byrow=T ) b = matrix( data=c(19,8), nrow=2 ) s_bb = solve( A, b ) x_extreme = c(s_gb[1], s_bb[1], 8, 20, 20) y_extreme = c(s_gb[2], s_bb[2], 0, 0 , 2) polygon( x_extreme, y_extreme, col='gray' ) grid() if( save_plots ){ dev.off() } for( ii in 1:(length(x_extreme)-2) ){ x = x_extreme[ii] y = y_extreme[ii] print( sprintf( "(%10.5f, %10.5f) has cost %10.6f", x_extreme[ii], y_extreme[ii], x + 0.25*y ) ) } print( "Chapter 7: Section 3: Exercise 10" ) # x = seq( from=-0.5, to=50000, length.out=100 ) y = ( 400 - 0.01 * x ) / 0.02 if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_3_prob_10.eps", onefile=FALSE, horizontal=FALSE) } plot( x, y, type='l', ylim=c(-1000,20000), xlim=c(-500,30000), xlab='x_1', ylab='x_2' ) y = ( 450 - 0.03 * x ) / 0.01 lines( x, y, type='l', col='blue' ) y = ( 480 - 0.03 * x ) / 0.015 lines( x, y, type='l', col='red' ) abline( h=0 ) abline( v=0 ) # The intersection of the red and black lines: A = matrix( data=c(0.01,0.02,0.03,0.015), nrow=2, ncol=2, byrow=T ) b = matrix( data=c(400,480), nrow=2 ) s_rb = solve( A, b ) # The intersection of the red and blue lines: A = matrix( data=c(0.03,0.01,0.03,0.015), nrow=2, ncol=2, byrow=T ) b = matrix( data=c(450,480), nrow=2 ) s_rblue = solve( A, b ) x_extreme = c(0 , s_rb[1], s_rblue[1], 15000, 0 ) y_extreme = c(20000, s_rb[2], s_rblue[2], 0 , 0 ) polygon( x_extreme, y_extreme, col='gray' ) grid() if( save_plots ){ dev.off() } for( ii in 1:length(x_extreme) ){ x = x_extreme[ii] y = y_extreme[ii] print( sprintf( "(%10.0f, %10.0f) has profit (dollars) %10.0f", x_extreme[ii], y_extreme[ii], ( 10 * x + 15 * y ) / 100 ) ) }