# # 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 10: Exercise 1 (e) # p1 = seq( from=0, to=1, length.out=100 ) E1 = 4 - 3 * p1 E2 = 2 * rep( 1, length(p1) ) E3 = 1 + 2 * p1 max_E = max( c(E1,E2,E3) ) min_E = min( c(E1,E2,E3) ) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_10_exercise_1_Part_e.eps", onefile=FALSE, horizontal=FALSE) } plot( p1, E1, type='l', col='blue', xlim=c(-0.1,+1.1), ylim=c(min_E,max_E), xlab='p_1', ylab='expectation' ) lines( p1, E2, type='l', col='red' ) lines( p1, E3, type='l', col='purple' ) abline( v=0 ) abline( v=1.0 ) polygon( c(0,0.5,2/3,1.0), c(1.0,2.0,2.0,1.0), col='gray' ) grid() if( save_plots ){ dev.off() } # Chapter 7: Section 10: Exercise 2 (a) # q1 = seq( from=0, to=1, length.out=100 ) E1 = 15*(1-q1) E2 = 8*q1 E3 = 20 - 30*q1 E4 = 12 - 2*q1 max_E = max( c(E1,E2,E3,E4) ) min_E = min( c(E1,E2,E3,E4) ) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_10_exercise_2_Part_a.eps", onefile=FALSE, horizontal=FALSE) } plot( q1, E1, type='l', col='blue', xlim=c(-0.1,+1.1), ylim=c(min_E,max_E), xlab='q_1', ylab='expectation' ) lines( q1, E2, type='l', col='red' ) lines( q1, E3, type='l', col='purple' ) lines( q1, E4, type='l', col='cyan' ) abline( v=0 ) abline( v=1.0 ) polygon( c(0.0,2/7,1.0,1.0), c(25,12-4/7,10,25), col='gray' ) grid() if( save_plots ){ dev.off() } # Chapter 7: Section 10: Exercise 2 (b) # p1 = seq( from=0, to=1, length.out=100 ) E1 = -2 + p1 E2 = 1 - 3 * p1 E3 = rep( 0, length(p1) ) E4 = 2 - 5 * p1 E5 = 5 - 9 * p1 max_E = max( c(E1,E2,E3,E4,E5) ) min_E = min( c(E1,E2,E3,E4,E5) ) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_10_exercise_2_Part_b.eps", onefile=FALSE, horizontal=FALSE) } plot( p1, E1, type='l', col='blue', xlim=c(-0.1,+1.1), ylim=c(min_E,max_E), xlab='p_1', ylab='expectation' ) lines( p1, E2, type='l', col='red' ) lines( p1, E3, type='l', col='purple' ) lines( p1, E4, type='l', col='cyan' ) lines( p1, E5, type='l', col='black' ) abline( v=0 ) abline( v=1.0 ) polygon( c(0,0,2/3,3/4,1,1), c(-5,-2,-4/3,-7/4,-4,-5), col='gray' ) grid() if( save_plots ){ dev.off() } # Chapter 7: Section 10: Exercise 2 (c) # p1 = seq( from=0, to=1, length.out=100 ) E1 = -6 + 11 * p1 E2 = - p1 E3 = 8 - 10 * p1 E4 = -9 + 17 * p1 max_E = max( c(E1,E2,E3,E4) ) min_E = min( c(E1,E2,E3,E4) ) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_10_exercise_2_Part_c.eps", onefile=FALSE, horizontal=FALSE) } plot( p1, E1, type='l', col='blue', xlim=c(-0.1,+1.1), ylim=c(min_E,max_E), xlab='p_1', ylab='expectation' ) lines( p1, E2, type='l', col='red' ) lines( p1, E3, type='l', col='purple' ) lines( p1, E4, type='l', col='black' ) abline( v=0 ) abline( v=1.0 ) polygon( c(0,0,1/2,8/9,1,1), c(-10,-9,-1/2,-8/9,-2,-10), col='gray' ) grid() if( save_plots ){ dev.off() } # Chapter 7: Section 10: Exercise 3 # p1 = seq( from=0, to=1, length.out=100 ) E1 = 3 - 2 * p1 E2 = rep( 2, length(p1) ) E3 = 1 + 2 * p1 max_E = max( c(E1,E2,E3) ) min_E = min( c(E1,E2,E3) ) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_10_exercise_3.eps", onefile=FALSE, horizontal=FALSE) } plot( p1, E1, type='l', col='blue', xlim=c(-0.1,+1.1), ylim=c(min_E,max_E), xlab='p_1', ylab='expectation' ) lines( p1, E2, type='l', col='red' ) lines( p1, E3, type='l', col='purple' ) abline( v=0 ) abline( v=1.0 ) polygon( c(0,0,0.5,1,1), c(0,1,2.0,1.0,0), col='gray' ) grid() if( save_plots ){ dev.off() } # Chapter 7: Section 10: Exercise 4 # q1 = seq( from=0, to=1, length.out=100 ) E1 = -7 + 20 * q1 E2 = 8 - 5 * q1 E3 = 14 - 15 * q1 E4 = -1 + 10 * q1 max_E = max( c(E1,E2,E3,E4) ) min_E = min( c(E1,E2,E3,E4) ) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_10_exercise_4.eps", onefile=FALSE, horizontal=FALSE) } plot( q1, E1, type='l', col='blue', xlim=c(-0.1,+1.1), ylim=c(min_E,max_E), xlab='q_1', ylab='expectation' ) lines( q1, E2, type='l', col='red' ) lines( q1, E3, type='l', col='purple' ) lines( q1, E4, type='l', col='black' ) abline( v=0 ) abline( v=1.0 ) polygon( c(0,0,0.6,1,1), c(15,14,5,13,15), col='gray' ) grid() if( save_plots ){ dev.off() } # Chapter 7: Section 10: Exercise 5 # q1 = seq( from=0, to=1, length.out=100 ) E1 = 1 - 2 * q1 E2 = -2 + 4 * q1 E3 = 3 - 6 * q1 E4 = -4 + 8 * q1 max_E = max( c(E1,E2,E3,E4) ) min_E = min( c(E1,E2,E3,E4) ) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_10_exercise_5.eps", onefile=FALSE, horizontal=FALSE) } plot( q1, E1, type='l', col='blue', xlim=c(-0.1,+1.1), ylim=c(min_E,max_E), xlab='q_1', ylab='expectation' ) lines( q1, E2, type='l', col='red' ) lines( q1, E3, type='l', col='purple' ) lines( q1, E4, type='l', col='purple' ) abline( v=0 ) abline( v=1.0 ) #polygon( c(0,0,0.5,1.0,1.0), c(1.0,-1.0,-1.5,0.0,1.0), col='gray' ) grid() if( save_plots ){ dev.off() } # Chapter 7: Section 10: Exercise 9 Part (c) # q1 = seq( from=0, to=1, length.out=100 ) E1 = -3 + 3 * q1 E2 = -1 - q1 E3 = -3 + q1 max_E = max( c(E1,E2,E3) ) min_E = min( c(E1,E2,E3) ) if( save_plots ){ postscript("../../WriteUp/Graphics/Chapter7/section_10_exercise_9_Part_c.eps", onefile=FALSE, horizontal=FALSE) } plot( q1, E1, type='l', col='blue', xlim=c(-0.1,+1.1), ylim=c(min_E,max_E), xlab='q_1', ylab='expectation' ) lines( q1, E2, type='l', col='red' ) lines( q1, E3, type='l', col='purple' ) abline( v=0 ) abline( v=1.0 ) polygon( c(0,0,0.5,1.0,1.0), c(1.0,-1.0,-1.5,0.0,1.0), col='gray' ) grid() if( save_plots ){ dev.off() }