s := 1 This is required for some plots below. Supplement to 16.881 Homework#2 Exploration of the Quadratic Loss Function Dan Frey, 6 JUN 98 The areas I expect you'll need to change to do homework#2 are highlighted. ORIGIN := 1 Let 1 be the first index in any vector. A o := 10 Cost to scrap the resistor [cents] m := 100 Nominal value of the resistance (in ohms) D o := 5%�m Allowable variation in the diameter is +/- 5% Ao k1 := k2 := 2 Do L(y) := Ao 2 Do k1�(y - m) 2 k2�(y - m) 2 if y > m Define the quadratic loss function if y £ m y := m - 1.2�D o , m - 1.2�D o + Do 10 .. m + 1.2�D o Define a range over y for the purpose of plotting Quadratic Loss Function m- D o m+ D o 10 L(y) 5 0 94 96 98 100 102 y 1 104 106 Create a Monte Carlo simulation of the manufacture of the resistors. n := 1000 s := Number of resistors to be manufactured Do 6 m := m + 1.5� s R := rnorm( n , m , s) Create a vector with all of the resistance values of the resistors we manufactured. Set up the format for a histogram of the data. number_of_bins := 20 width_of_bins := 4�D o number_of_bins j := 1.. number_of_bins + 1 bin := m - 2�D o + width_of_bins� j j rel_freq := hist(bin , R) n Define a vector with the start and end points of the bins. Compute the relative frequency distribution over interval. bin_center := bin + 0.5� width_of_bins 2 Simulation Results for the Resistors m- D o L( y) m+ D o 1 Ao rel_freq 0.5 0 90 95 100 105 110 115 y , bin_center Average_quality_loss := 1 n n � � L(Ri) i=1 Average_quality_loss = 0.845 in cents How does this compare to the theoretically derived figure? m+ 2�D o � � � � � ım-2�D 2 Ø - (y-m ) ø Œ œ 2 œ 1 2Œ 2�s k1�(y - m) � Œ �e œ dy = 0.903 º s� 2�p ß o 3 in cents