palm_ch4

# palm_ch4 - Solutions to Problems in Chapter Four Test Your...

This preview shows pages 1–6. Sign up to view the full content.

Solutions to Problems in Chapter Four Test Your Understanding Problems T4.2-1 The session is ± x = [5,-3,18,4];y = [-9,13,7,4]; ± z = ~y>x z= 0100 ± z = x&y 1111 ± z = x|y ± z = xor(x,y) 0000 T4.2-2 The script ﬁle is identical to that used in Example 4.2-1 except for the line u= find(~(h<4|v>17)); . v0 = 20;g = 9.81;A = 40*pi/180; t_hit = 2*v0*sin(A)/g; t = [0:t_hit/100:t_hit]; h = v0*t*sin(A)-0.5*g*t.^2; v = sqrt(v0^2-2*v0*g*sin(A)*t+g^2*t.^2); u = find(~(h<4|v>17)); t_1 = (u(1)-1)*(t_hit/100) t_2 = u(length(u)-1)*(t_hit/100) The results are t 1 =0 . 5766 and t 2 =2 . 0443. Thus h< 4or v> 17 for t<t 1 and for t>t 2 . T4.3-1 x = 13; if x>10 y = log(x) if y>= 3 z = 4*y elseif y >2.5 z = 2*y 4-1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
else z=0 end else y = 5*x z = 7*x end T4.3-2 Note that the asin(x) function returns the correct value (in radians) only if x is in the ﬁrst or fourth quadrant. Note also that it is possible to give incompatible values for q and x . For example, q cannot equal 1 if x< 0. The following script ﬁle protects against this error. if x> = 0&x<1 if q==1 y = asin(x)*180/pi; elseif q==2 y = asin(x)*180/pi + 270; end if q==3|q==4 disp( 0 Incompatible values of x and q 0 ) else disp(y) end elseif x<0&x>-1 if q==4 y = asin(x)*180/pi; else y = asin(x)*180/pi -90; end if q==1|q==2 disp( 0 Incompatible values of x and q 0 ) else disp(y) end else disp( 0 The magnitude of x is greater than 1 0 ) end 4-2
T4.4-1 The script ﬁle is m=0; for q = 0:6:18 m = m+1; n=0; for r = 4:4:12 n = n+1; A(m,n) = r+q; end end T4.4-2 The script ﬁle is [m,n] = size(A); for c = 1:n x=0; for r = 1:m x = x + A(r,c); end sum_A(c) = x; end disp(sum_A) T4.4-3 The script ﬁle is x = 49; k=1; while x>0 y = sqrt(x) k = k+1; x = 50 - k^2; end T4.4-4 The script ﬁle is error = 0; while error < 1 x = x + .01; approx = 1 + x + x^2/2 + x^3/6; error = 100*(exp(x) - approx)/exp(x); 4-3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
end disp(x) T4.5-1 The script ﬁle is angle = input( 0 Enter an angle in degrees. 0 ) switch angle case 45 disp( 0 Angle is in first quadrant 0 ) case -45 disp( 0 Angle is in second quadrant 0 ) case 135 disp( 0 Angle is in third quadrant 0 ) case -135 disp( 0 Angle is in fourth quadrant 0 ) otherwise disp( 0 Quadrant is unknown. 0 ) end T4.7-1 The 0.75 in the matrix should be replaced with 0.70. T4.7-2 Initial values of a and d are needed in case the statements following the else statement are executed (these statements are a(k) = a(k-1) , d(k) = d(k-1) ). End-of-Chapter Problems 1. The answers are (a) z=1 ,(b) z=0 , (c) ,(d) 2. The answers are (a) , (c) , (d) z=4 , (e) ,( f) z=5 , (g) ,(h) 3. The answers are (a) z = [ 0,1,0,1,1] z = [ 0,0,0,1,1 ] , (c) z = [0,0,0,1,0] z = [1,1,1,0,1] , 4. The session is ± x = [-3,0,0,2,6,8]; ± y = [-5,-2,0,3,4,10]; ± n = find(x>y) n= 125 Thus the ﬁrst, second, and ﬁfth elements of x are greater than the corresponding elements in y . 4-4
5. The session is ± price = [19,18,22,21,25,19,17,21,27,29]; ± length(find(price>20)) ans = 6 Thus the price was over \$20 on six days. 6. The session is ± price_A = [19,18,22,21,25,19,17,21,27,29]; ± price_B = [22,17,20,19,24,18,16,25,28,27]; ± length(find(price_A>price_B)) ans = 7 7. (a) The session is ± price_A = [19,18,22,21,25,19,17,21,27,29]; ± price_B = [22,17,20,19,24,18,16,25,28,27]; ± price_C = [17,13,22,23,19,17,20,21,24,28]; ± length(find(price_A>price_B&price_A>price_C)) ans = 4 Thus the price of stock A was above both B and C on four days. (b) Replace the fourth line in the above session with ± length(find(price_A>price_B|price_A>price_C)) ans = 9 Theanswerisn inedays .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/21/2009 for the course ENGR 290 taught by Professor Priritera during the Spring '05 term at S. Alabama.

### Page1 / 36

palm_ch4 - Solutions to Problems in Chapter Four Test Your...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online