Sie sind auf Seite 1von 28

Solutions to Problems in Chapter Seven

Solutions to Test Your Understanding Problems T7.1-1 The script le for the absolute histogram is y = [91*ones(1,7), 92*ones(1,8), 93*ones(1,10),... 94*ones(1,6), 95*ones(1,12), 96*ones(1,7)]; x = [91:96]; hist(y,x),ylabel( Absolute Frequency ),xlabel( Thread Strength (newtons) )

The plot is shown in the gure.


12

10

Absolute Frequency

0 90

91

92

93 94 Thread Strength (newtons)

95

96

97

Figure : for Problem T7.1-1a. The script le for the relative histogram is tests = 50; y = [7, 8, 10, 6, 12]/tests; x = [91:96]; bar(x,y),ylabel( Relative Frequency ),xlabel( Thread Strength (newtons) )

7-1

0.25

0.2

Relative Frequency

0.15

0.1

0.05

0 90

91

92

93 94 Thread Strength (newtons)

95

96

97

Figure : for Problem T7.1-1b. The plot is shown in the gure. T7.1-2 (a) 200(6/36) 33 times. (b) 200(4 + 3 + 2)/36 50 times. (c) 200(1 + 2 + 3 + 4 + 5)/36 106 times. T7.2-1 (a) The script le is y_abs = [1,1,2,0,3,4,5,6,8,11,12,10,11,8,7,5,4,4,4,1,2,0,1]; binwidth = .5; area = binwidth*sum(y_abs); y_scaled = y_abs/area; bins = [64:binwidth:75]; bar(bins,y_scaled),ylabel( Scaled Frequency ),xlabel( Height (inches) ) The plot is shown in the gure. (b) The script le is y_abs = [1,1,2,0,3,4,5,6,8,11,12,10,11,8,7,5,4,4,4,1,2,0,1]; binwidth = .5; bins = [64:binwidth:75]; y_raw = []; 7-2

0.25

0.2

Scaled Frequency

0.15

0.1

0.05

0 62

64

66

68 70 Height (inches)

72

74

76

Figure : for Problem T7.2-1a. for i = 1:length(y_abs) if y_abs(i)>0 new = bins(i)*ones(1,y_abs(i)); else new = []; end y_raw = [y_raw,new]; end mu = mean(y_raw),sigma = std(y_raw) Running this le gives a mean of 69.4 and a standard deviation of 2.14. (c) and (d) Running the following script le gives the answers: 43% and 63%. mu = 69.4; sigma = 2.14; b1 = 69; P1 = (1+erf((b1-mu)/(sigma*sqrt(2))))/2 a2 = 68; b2 = 72; P2 = (erf((b2-mu)/(sigma*sqrt(2))) - erf((a2-mu)/(sigma*sqrt(2))))/2 7-3

T7.3-1 Note that y = (15 + 5)x 5 = 20x 5. Thus the session is y = 20*rand(1,1500)-5; mean(y) min(y) max(y) The computed mean, minimum, and maximum should be close to, but not exactly equal to, 5, 5, and 15, respectively. T7.3-2 In the program given in Example 7.3-1, change the line income = 4000*demand + 1000*(level(k)- demand); to income = 4000*demand + 2000*(level(k)-demand);. The resulting plot is shown in the gure. From this we can see that the optimum production level is 50 units per season and the prot will be $46,000.
5 x 10
4

4.5

Profit ($)

3.5

2.5

2 25

30

35 No. of Units

40

45

50

Figure : for Problem T7.3-2.

7-4

T7.3-3 Note that y = 10x + 7. Thus the session is y = 10*randn(1,1800)+7; mean(y) std(y) The computed mean and standard deviation should be close to, but not exactly equal to, 7 and 10, respectively. The theoretical minimum and maximum of the normal distribution is and + respectively, but a computer simulation cannot produce such numbers. Solutions to End of Chapter Problems 1. The script le for the absolute frequency histogram is data = [22*ones(1,2), 23*ones(1,3), 24*ones(1,6), 25*ones(1,5), ... 26*ones(1,4), 27*ones(1,2)]; x=[min(data):max(data)]; hist(data,x),ylabel( Absolute Frequency ),... xlabel( Gas Mileage (miles per gallon) ) The plot is shown in the gure.
6

Absolute Frequency

0 21

22

23

24 25 26 Gas Mileage (miles per gallon)

27

28

Figure : for Problem 7.1a. The script le for the relative frequency histogram is data = [22*ones(1,2), 23*ones(1,3), 24*ones(1,6), 25*ones(1,5), 26*ones(1,4), ... 7-5

27*ones(1,2)]; tests=length(data); x = [min(data):max(data)]; [z,x] = hist(data,x);bar(x,z/tests),... ylabel( Relative Frequency ),xlabel( Gas Mileage (miles per gallon) ) The plot is shown in the gure.

0.3

0.25

Relative Frequency

0.2

0.15

0.1

0.05

0 21

22

23

24 25 26 Gas Mileage (miles per gallon)

27

28

Figure : for Problem 7.1b.

7-6

2. The script le for the absolute frequency histogram using a bin width of 50 is data = [243,236,389,628,143,417,205,... 404,464,605,137,123,372,439,... 497,500,535,577,441,231,675,... 132,196,217,660,569,865,725,457,347]; spread = max(data)-min(data); binwidth = 50; n = round(spread/binwidth) hist(data,n),ylabel( Absolute Frequency ),xlabel( Timber Breaking Strength (lbs) ) To use binwidths of 100 and 200, change the variable binwidth in the above le. The three plots are shown in the gures.
4

3.5

Absolute Frequency

2.5

1.5

0.5

0 100

200

300

400 500 600 Timber Breaking Strength (lbs)

700

800

900

Figure : for Problem 7.2a.

7-7

Absolute Frequency

0 100

200

300

400 500 600 Timber Breaking Strength (lbs)

700

800

900

Figure : for Problem 7.2b.

10 9 8 7

Absolute Frequency

6 5 4 3 2 1 0 100

200

300

400 500 600 Timber Breaking Strength (lbs)

700

800

900

Figure : for Problem 7.2c.

7-8

3. The script le for the absolute frequency histogram using a bin width of 10 is data=[311,138,340,199,270,255,332,279,231,296,198,269,... 257,236,313,281,288,225,216,250,259,323,280,205,... 279,159,276,354,278,221,192,281,204,361,321,282,... 254,273,334,172,240,327,261,282,208,213,299,318,... 356,269,355,232,275,234,267,240,331,222,370,226]; spread = max(data)-min(data); binwidth = 10; n = round(spread/binwidth); hist(data,n),ylabel( Absolute Frequency ),... xlabel( Cord Breaking Strength (newtons) ) To use binwidths of 30 and 50, change the variable binwidth in the above le. The three plots are shown in the gures.
7

Absolute Frequency

0 100

150

200 250 300 Cord Breaking Strength (newtons)

350

400

Figure : for Problem 7.3a.

7-9

20 18 16 14

Absolute Frequency

12 10 8 6 4 2 0 100

150

200 250 300 Cord Breaking Strength (newtons)

350

400

Figure : for Problem 7.3b.

20 18 16 14

Absolute Frequency

12 10 8 6 4 2 0 100

150

200 250 300 Cord Breaking Strength (newtons)

350

400

Figure : for Problem 7.3c.

7-10

4. (a) 300(5/36) 42 times. (b) 300(2 + 3 + 4)/36 75 times. (c) 300(1 + 2 + 3 + 4 + 5 + 6 + 5)/36 217 times. 5. (a) The m-le is data = [22*ones(1,2),23*ones(1,3),24*ones(1,6),... 25*ones(1,5),26*ones(1,4),27*ones(1,2)]; x = [min(data):max(data)]; [y_abs,x] = hist(data,x); binwidth = 1; area = binwidth*sum(y_abs); y_scaled = y_abs/area; bins = [min(data):binwidth:max(data)]; bar(bins,y_scaled),ylabel( Scaled Fequency ),xlabel( Mileage (mpg) ) mu = mean(data) sigma = std(data) The plot is shown in the gure. (b) The results are mu = 24.5455 and sigma = 1.4385. Thus if the data is normally distributed, 68% of the data should lie between 24.5455 1.4385 = 23.107 and 24.5455 1.4385 = 25.984. The area under the plot between 23 and 26 mpg is (0.14+0.27+0.22)(1) = 0.8182. Thus 82% of the data lies between 23 and 26 mpg. Given the wide binwidth, it is dicult to say whether or not the distribution is normal.

0.3

0.25

0.2

Scaled Fequency

0.15

0.1

0.05

0 21

22

23

24 25 Mileage (mpg)

26

27

28

Figure : for Problem 7.5.

7-11

6. (a) The m-le is given below. A bin width of 100 was chosen as a compromise between 50 (which gave gaps in the histogram) and 200 (which removes too much detail from the histogram). data = [243,236,389,628,143,417,205,... 404,464,605,137,123,372,439,... 497,500,535,577,441,231,675,... 132,196,217,660,569,865,725,457,347]; x = [100:100:800]; [y_abs,x] = hist(data,x); binwidth = 100; area = binwidth*sum(y_abs); y_scaled = y_abs/area; bins = x; bar(bins,y_scaled),ylabel( Scaled Fequency ),xlabel( Breaking Force (lbs) ) mu = mean(data) sigma = std(data) The histogram is shown in the gure. The results are mu = 414.3000 and sigma = 198.4462. (b) + = 612.7462, = 215.8538, + 2 = 811.1925, and 2 = 17.4075. The area under the plot between 200 and 600 lbs is (0.002+0.0003+0.002+0.0017+0.0013)100 = 0.73. Thus 73% of the data lies bewtenn 200 and 600 lbs. The bin width is too great to use the 2 comparison. The distribution is not normal because it is not symmetric and because of the large gap at 300 lbs.
2 1.8 1.6 1.4 x 10
3

Scaled Fequency

1.2 1 0.8 0.6 0.4 0.2 0 0

100

200

300

400 500 Breaking Force (lbs)

600

700

800

900

Figure : for Problem 7.6.

7-12

7. (a) The m-le is given below. A bin width of 50 was chosen because bin widths of 10 and 30 are too narrow for the small data set. data = [311,138,340,199,270,255,332,279,231,296,198,269,... 257,236,313,281,288,225,216,250,259,323,280,205,... 279,159,276,354,278,221,192,281,204,361,321,282,... 254,273,334,172,240,327,261,282,208,213,299,318,... 356,269,355,232,275,234,267,240,331,222,370,226]; x = [150:50:350]; [y_abs,x] = hist(data,x); binwidth = 50; area = binwidth*sum(y_abs); y_scaled = y_abs/area; bins = x; bar(bins,y_scaled),ylabel( Scaled Fequency ),xlabel( Breaking Force (newtons) ) mu = mean(data) sigma = std(data) The histogram is shown in the gure. The results are mu = 266.9500 and sigma = 52.8212 . + = 319.7712, = 214.1288, + 2 = 372.5925, and 2 = 161.3075. The area under the plot between 200 and 300 newtons is (0.0037 + 0.0063 + 0.0057)50 = 0.785. Thus 78.5% of the dat lies between 200 and 300 newtons. This is close to the 68% predicted by the normal distribution, but this data is not normally distributed because the plot is not symmetric. The bin width is too great to use the 96% prediction.
7 x 10
3

Scaled Fequency

0 100

150

200 250 300 Breaking Force (newtons)

350

400

Figure : for Problem 7.7.

7-13

8. = 200, = 3. (a) Note that 194 = 2. Thus 99% will have a breaking strength no less than 194 pounds. (b) Note that 197 = and 203 = + . Thus 68% will have a breaking strength no less than 197 pounds and no greater than 203 pounds. 9. = 50, = 5. Note that 60 = + 2. Thus it will take more than 60 minutes 2% of the time. 10. = 5.007, = 0.005. Note that 5 0.01 = 2. Thus 96% of the ttings will be within tolerance.
2 11. For the shaft of diameter d1 , the mean and variance are 1 = 3 and 1 = 0.0064. Thus 1 = 0.08. For the shaft of diameter d2 , the mean and variance are 2 = 2.96 and 2 2 = 0.0036. Thus 2 = 0.06. 2 (a) Let c and c be the mean and the variance of the clearance c = d1 d2 . Then 2 2 2 c = 1 2 = 3 2.96 = 0.04, and c = 1 + 2 = 0.0064 + 0.0036 = 0.01. Thus c = 0.1. (b) Find P (c < 0).

P (c < 0) =

1 1 + erf 2

c c 2

1 1 + erf 2

0.04 0.1 2

The Matlab session to evaluate this is (1+erf(-.04/(.1*sqrt(2))))/2 The answer given is 0.3446. Thus a shaft will not t into the bearing 34.46% of the time. 12. The mean and standard deviation of the part weight are = 1 and = 0.2. (a) Because the pallet weight is the sum of the part weights, the mean and variance of the 2 pallet weight are given by p = 10(300) = 3000 pounds, and p = 10(300) 2 = 120. Thus p = 120 = 10.95 pounds. (b) The probability that the pallet weight W exceeds 3015 pounds is given by P (W > 3015) = 1 P (W 3015) = 1 The Matlab session to evaluate this is 1-(1+erf(15/(sqrt(240))))/2 The answer given is 0.0855. Thus the pallet weight will exceed 3015 pounds 8.55% of the time. 13. (a) Because the length is the sum of the lengths of the individual pieces, the means and the variances are additive. Thus the mean and variance of the total length are = 1 + 2 + 1.5 = 4.5 feet and 2 = 1.4 104 + 2 104 + 3 104 = 6.4 104 . Thus = 0.0253 foot. 7-14 1 1 + erf 2 3015 3000 120 2

(b) The answer is given by P (4.48 L 4.52) = 1 erf 2 4.52 4.5 2 erf 4.48 4.5 2

The Matlab session to evaluate this is (erf(.02/sqrt(2*.00064))-erf(- .02/sqrt(2*.00064)))/2 The answer given is 0.5708. Thus the length of the assembled products will be no less than 4.48 and no more than 4.52 feet 57.08% of the time. 14. The session is y = 16*rand(1,1000)+2; mean(y) ans = 10.1261 x = [2:18]; hist(y,1x),xlabel( Random Values ),ylabel( Absolute Frequency ) The computed mean is 10.1261, whereas the true mean is 10. You will obtain dierent results every time you run this session. The histogram is shown in the gure. The bin spacing x = [2:18] was chosen to show the distribution of the integer values between the minimum of 2 and the maximum of 18. Note that the bins for the minimum value 2 and the maximum value 18 are smaller in height than the other bins because the hist(y,x) function with x = [2:18] rounds o to the nearest integer. Because the line y = 16*rand(1,1000)+2 cannot produce any values less than 2 or greater than 18, these two end bins will be smaller than the others.
80

70

60

Absolute Frequency

50

40

30

20

10

0 0

8 10 12 Random Values

14

16

18

20

Figure : for Problem 7.14.

7-15

15. The m-le is n = 1000; y=2*randn(1,n)+20; mean_y = mean(y) s = std(y); variance_y = s^2 x = [round(min(y)):round(max(y))]; hist(y,x),xlabel( Random Values ),ylabel( Absolute Frequency ) disp( The percent within one standard deviation of the mean is ) percent = 100*sum((y>=(mean_y-s))&(y<=(mean_y+s)))/n The bin centers in x are selected at the integer values between the minimum and maximum random values produced by the simulation. The results give a mean 19.8754, as compared to the true value of 20, and a variance of 4.3326, as compared to the true value of 4. The percentage of values within one standard deviation of the mean is 67.9%, as compared to the true value of 68.3%. You will obtain dierent results every time you run this le.
200 180 160 140

Absolute Frequency

120 100 80 60 40 20 0 12

14

16

18

20 22 Random Values

24

26

28

Figure : for Problem 7.15.

7-16

16. The m-le is m = 100; x = sqrt(2)*randn(1,m)+10; y = sqrt(3)*randn(1,m)+15; z = x+y; mean_z = mean(z) variance = std(z)^2 When this le is run, the computed mean is 24.8294 and the computed variance is 5.5423. Changing the rst line to m = 1000 produces a computed mean of 25.0910 and a computed variance of 5.0666. Changing the rst line to m = 5000 produces a computed mean of 25.0241 and a computed variance of 4.9337. The true mean and variance are 25 and 5. Note how the computed values approach the true values as the number of random samples is increased. 17. The m-le is m = 100; x = sqrt(2)*randn(1,m)+10; y = sqrt(3)*randn(1,m)+15; z = x.*y; mean_z = mean(z) variance = std(z)^2 When this le is run, the computed mean is 149.3494 and the computed variance is 784.7786. Changing the rst line to m = 1000 produces a computed mean of 150.3036 and a computed variance of 774.2139. Changing the rst line to m = 5000 produces a computed mean of 149.8586 and a computed variance of 737.6167. Thus the mean of z = xy appears to be the product of the means of x and y [10(15) = 150], but the variance of z is neither the product nor the sum of the variances of x and y. 18. The m-le is m = 100; x = 2*randn(1,m); y = x.^2; mean_z = mean(z) variance = std(z)^2 When this le is run, the computed mean is 3.6706 and the computed variance is 25.5024. Changing the rst line to m = 1000 produces a computed mean of 4.2500 and a computed 7-17

variance of 35.9280. Changing the rst line to m = 5000 produces a computed mean of 4.1279 and a computed variance of 36.8581. Thus the mean of y = x2 is not the square of the mean of x, and the variance of y is not the square of the variance of x. 19. The script le shown below uses two for loops. The inner loop with the variable k computes the oucome of the strategy for 250 days. The outer loop with the variable p varies the seed value. It has the eect of computing the average yearly outcome over n years. The rst step in the inner loop is to create the vector price that has the 250 random values with a mean of 100 and standard deviation of 5. The loop contains if statements to check the price and the number of shares held, and to direct the ow accordingly. The cost of buying new shares is in the vector cost_new_shares. The income from selling shares is in the vector income_selling, and the number of shares held is in the vector shares. The prot is the dierence between the income from selling and the cost of buying shares. m = 100;s = 5; n = 100; for p = 1:n randn( seed ,p) price = s*randn(1,250) + m; shares_held = 0; income_selling = zeros(1,250); cost_new_shares = zeros(1,250); commission = zeros(1,250); for k = 1:250 if price(k) < 100 shares_held = shares_held + 50; commission(k) = max([40, .06*50]); cost_new_shares(k) = 50*price(k) + commission(k); shares(k)=shares_held; end if (price(k) > 105)&(shares_held > 0) commission(k) = max([40, .06*shares_held]); income_selling(k) = shares_held*price(k) - commission(k); shares_held = 0; shares(k)=shares_held; elseif (price(k) > 105)&(shares_held <= 0) shares(k)=shares_held; commission(k) = 0; end end cost(p) = sum(cost_new_shares); income(p) = sum(income_selling); 7-18

profit(p) = income(p) - cost(p) + price(250)*shares_held; total_commission(p) = sum(commission); end mean_yearly_profit = mean(profit) min_yearly_profit = min(profit) max_yearly_profit = max(profit) std_profit = std(profit) man_yearly_comm = mean(total_commission) Using a value of n = 100, the results are as follows. The mean yearly prot you would expect to make is $64,609, the minimum expected yearly prot is $51,340, the maximum expected yearly prot is $79,440, and the standard deviation of the yearly prot is $5967. The mean yearly commission paid is $6172. You might obtain dierent values because of the eect of the random number seed obtained from dierent processors. Because this is a random number simulation, the value used for n will aect the results. Larger values of n will give more reliable results. You can run the simulation for increasing values of n until the results stop changing. This will indicate when you have a large enough value for n. 20. The script le shown below uses two for loops. The inner loop with the variable k computes the oucome of the strategy for 250 days. The outer loop with the variable p varies the seed value. It has the eect of computing the average yearly outcome over n years. The rst step in the inner loop is to create the vector price that has the 250 random values with a mean of 150 and standard deviation of 10. The loop contains if statements to check the price and the number of shares held, and to direct the ow accordingly. The cost of buying new shares is in the vector cost_new_shares. The income from selling shares is in the vector income_selling, and the number of shares held is in the vector shares. The prot is the dierence between the income from selling and the cost of buying shares. The following m-le implements the rst strategy. To implement the second strategy, simply replace the eleventh line if price(k) < 140 with if price(k) < 150 m = 150;s = 10; n = 100; for p = 1:n randn( seed ,p) price = s*randn(1,250) + m; shares_held = 0; income_selling = zeros(1,250); cost_new_shares = zeros(1,250); commission = zeros(1,250); for k = 1:250 if price(k) < 140 shares_held = shares_held + 100; commission(k) = max([35, .05*100]); 7-19

cost_new_shares(k) = 100*price(k) + commission(k); shares(k)=shares_held; end if (price(k) > 160)&(shares_held > 0) commission(k) = max([35, .05*shares_held]); income_selling(k) = shares_held*price(k) - commission(k); shares_held = 0; shares(k)=shares_held; elseif (price(k) > 160)&(shares_held <= 0) shares(k)=shares_held; commission(k) = 0; end end cost(p) = sum(cost_new_shares); income(p) = sum(income_selling); profit(p) = income(p) - cost(p) + price(250)*shares_held; total_commission(p) = sum(commission); end mean_yearly_profit = mean(profit) min_yearly_profit = min(profit) max_yearly_profit = max(profit) std_profit = std(profit) man_yearly_comm = mean(total_commission) Using a value of n = 100, the results for the rst strategy are as follows. The mean yearly prot you would expect to make is $ 67,583, the minimum expected yearly prot is $42,796, the maximum expected yearly prot is $94,323, and the standard deviation of the yearly prot is $10,335. The mean yearly commission paid is $ 2507.80. You might obtain dierent values because of the eect of the random number seed obtained from dierent processors. Because this is a random number simulation, the value used for n will aect the results. Larger values of n will give more reliable results. You can run the simulation for increasing values of n until the results stop changing. This will indicate when you have a large enough value for n. Using a value of n = 100, the results for the second strategy are as follows. The mean yearly prot you would expect to make is $ 62,074, the minimum expected yearly prot is $36,636, the maximum expected yearly prot is $89,633, and the standard deviation of the yearly prot is $10,497. The mean yearly commission paid is $5025.30. 21. The function le flip is function [s, r1] = flip(s) rand( state ,s); if rand < 0.5 7-20

r1 = 1; else r1 = 0; end s = rand( state ); The function le flips is function [s, [s1,flip1] = [s2,flip2] = r2 = flip1 + s = s2; r2] = flips(s) flip(s); flip(s1); flip2;

The function le match is function [s, r3] = match(s) [s,r2] = flips(s); if r2 == 2 r3 = 1; elseif r2 == 0 r3 = 0; else [s,r1] = flip(s); r2 = r2 + r1; if r2 == 2 r3 = 1; end end

22. The script le is clear rand( state ,sum(100*clock)); x = randperm(15); number = x(1); k = 0;status = 0; disp( You will have 14 attempts to guess a number from 1 to 15. ) while(k < 14)&(status == 0) k = k+1; Turn = k 7-21

guess = input( Enter your guess (1 to 15) ) diff = abs(guess-number); if diff == 0 disp( You won! ) status = 1; elseif diff > 3 disp( Not close. ) status = 0; else status = 0; if (diff == 2)|(diff == 3) disp( Getting close. ) else disp( Very close. ) end end end if k >= 14 disp( You have no more guesses left. ) else disp( The number of guesses you took was ) disp(k) end

23. The session is x = [1:4,6:8,10:12]; y = [10,12,18,24,21,20,18,15,13,8]; x_int = [5,9]; interp1(x,y, x_int) ans = 22.5000 16.5000 Thus the estimated temperatures at 5 P.M. and 9 P.M. are 22.5 and 16.5 . 24. Note that with this data, because each column of data corresponds to a dierent day, it makes sense to interpolate only between the rows and not between the columns. The session is x2 = [1,3:5]; x4 = [1,2,4,5]; y2 = [15,14,15,18]; 7-22

y4 = [16,11,15,20]; y2est = interp1(x2,y2,2) y2est = 14.5000 y4est = interp1(x4,y4,3) y4est = 13 Thus the estimated temperature at 2 P.M. on Tuesday is 14.5 , and estimated temperature at 3 P.M. on Thursday is 13 . 25. Using equation (7.4-9), the equation for the straight line connecting the endpoints is y = 2(x 6)/3. The two knot points are at x = 2 and x = 4, which correspond to y = 8/3 and y = 4/3. To solve for the arm angles, use a modication of the rst program shown in Example 7.4-1. The m-le is % Solution for arm angles with two knot points. % Enter the arm lengths. L1 = 4;L2 = 3; % Enter the end points and the knot points x = [6,4,2,0];y = [0,4/3,8/3,4]; % Program equations (7.4-3) through (7.4-7). R = sqrt(x.^2+y.^2); theta2 = acos((R.^2-L1^2-L2^2)/(2*L1*L2))*(180/pi) beta = acos((R.^2+L1^2-L2^2)/(2*L1*R))*(180/pi); alpha = atan2(y,x)*(180/pi); if theta2 < 0 theta1 = alpha+beta else theta1 = alpha-beta end The results are: theta2 = 62.7204 107.5132 125.3594 112.0243 and theta1 = -37.2879 -18.8529 15.8422 52.7121. Next use these values with the following m-le, which is a modication of the second program shown in Example 7.4-1. % Robot arm spline problem with two knot points. % theta1 and theta2 are computed elsewhere. % Interpolate over time. t=[0,1,2,3]; t_i=linspace(0,3,300); % Compute the arm angles. 7-23

theta1_i=spline(t,theta1,t_i); theta2_i=spline(t,theta2,t_i); % Compute the hand s coordinates. x=4*cos(theta1_i*(pi/180))+3*cos((theta1_i+theta2_i)*(pi/180)); y=4*sin(theta1_i*(pi/180))+3*sin((theta1_i+theta2_i)*(pi/180)); % Compute the elbow s coordinates. elbowx=[4*cos(theta1_i*(pi/180))]; elbowy=[4*sin(theta1_i*(pi/180))]; % Compute the coordinates to display the arm s position at 4 points. xpos1=[0,elbowx(1),x(1)];ypos1=[0,elbowy(1),y(1)]; xpos2=[0,elbowx(100),x(100)];ypos2=[0, elbowy(100),y(100)]; xpos3=[0,elbowx(200),x(200)];ypos3=[0,elbowy(200),y(200)]; xpos4=[0,elbowx(300),x(300)];ypos4=[0,elbowy(300),y(300)]; % Plot the results. plot(x,y,xpos1,ypos1,xpos2,ypos2,xpos3,ypos3,xpos4,ypos4),... axis([0 7 -3 5]),title( Path of Robot Hand Using Two Knot Points ),... xlabel( x (feet) ),ylabel( y (feet) ),... gtext( START ),gtext( END ),gtext( Knot Point 1 ),gtext( Knot Point 2 ) The plot is shown in the gure. With only two knot points the hands path is not very close to a straight line. Use more knot points to obtain a straight path.

7-24

Path of Robot Hand Using Two Knot Points 5

END

Knot Point 2

Knot Point 1

y (feet)

START

3 x (feet)

Figure : for Problem 7.25a.

7-25

26. The m-le is x = [0,.25,.75,1.25,1.5,1.75,1.875,2,2.125,2.25]; y = [1.2,1.18,1.1,1,.92,.8,.7,.55,.35,0]; x_int = [0:.01:2.25]; y_int = spline(x,y,x_int); plot(x,y, o ,x_int,y_int),xlabel( x (ft) ),ylabel( y (ft) ),axis([0 2.25 0 1.5]); The plot is shown in the gure.
1.5

y (ft)
0.5 0 0

0.5

1 x (ft)

1.5

Figure : for Problem 7.26.

7-26

27. a) The script le is t = [0:10]; T = [72.5, 78.1, 86.4, 92.3, 110.6, 111.5, 109.3, 110.2, 110.5, 109.9, 110.2]; t_int = [0:.05:10]; T_int = spline(t,T,t_int); plot(t,T,t,T, * ,t_int,T_int),xlabel( Time (sec) ),ylabel( Temperature (deg F) ) The plot is shown in the gure.
115

110

105

100

Temperature (deg F)

95

90

85

80

75

70

5 Time (sec)

10

Figure : for Problem 7.27. b) Insert the following lines at the end of the script le from Part (a). t_est = [0.6,2.5,4.7,9.8]; T_est_spline = interp1(t,T,t_est, spline ) T_est_linear = interp1(t,T,t_est)

The results are T_est_spline = [74.7235, 88.2044, 112.6234, 109.9696] and T_est_linear = [75.8600, 89.3500, 111.2300, 110.1400]. c) Insert the folowing code after the ylabel command in part (a). 7-27

grid,[tlinear,Tlinear] = ginput(4),[tspline,Tspline] = ginput(4) and use the mouse to select the points corresponding to T = 75, 85, 90, and 105. The results are tlinear = [0.4493, 1.8088, 2.5922, 3.6982] and tspline = [0.6336, 1.7396, 2.7995, 3.6751].

7-28

Das könnte Ihnen auch gefallen