# M7solns4 - 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.3-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.3-2 The script fle is identical to that used in Example 4.3-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.4-1 Using x = 13 as a test case, the fle is: 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.4-2 Note that the asin(x) function returns the correct value (in radians) only if x is in the Frst or fourth quadrant. Note also that it is possible to give incompatible values for q and x . ±or example, q cannot equal 1 if x< 0. The following script Fle 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( ± Incompatible values of x and q ± ) 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( ± Incompatible values of x and q ± ) else disp(y) end else disp( ± The magnitude of x is greater than 1 ± ) end 4-2
T4.5-1 The script fle 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.5-2 The script fle 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.5-3 The script fle is x=49; k=1; while x>0 y = sqrt(x) k = k+1; x = 50 - k^2; end 4-3

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

View Full Document
T4.5-4 The script fle is error = 0; x=0; while error < 1 x = x + 0.01; approx = 1 + x + x^2/2 + x^3/6; error = 100*(exp(x) - approx)/exp(x); end disp(x) T4.6-1 The script fle is angle = input( ± Enter an angle in degrees. ± ) switch angle case 45 disp( ± Angle is in first quadrant ± ) case -45 disp( ± Angle is in second quadrant ± ) case 135 disp( ± Angle is in third quadrant ± ) case -135 disp( ± Angle is in fourth quadrant ± ) otherwise disp( ± Quadrant is unknown. ± ) end T4.8-1 The 0.75 in the matrix should be replaced with 0.70. T4.8-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. a) The pseudocode is: 1. Enter the range For r , aFter choosing an appropriate step size (here, a step size oF 0.01 m will give 301 values, enough to generate a smooth plot. r = [0:0.01:3]; 2. Code the Formulas For V and A . V = 4*pi*r.^3/3; A = 4*pi*r.^2; 4-4
3. Plot the results. plot(A,V),xlabel( ± Area (m^2) ± ),ylabel( ± Volume (m^3) ± ) b) The program is: r = [0:0.01:3]; V = 4*pi*r.^3/3; A = 4*pi*r.^2; plot(A,V),xlabel( ± Area (m^2) ± ),ylabel( ± Volume (m^3) ± ) 2. a) The pseudocode is: 1. Prompt the user to enter the coeﬃcients. Be sure to specify the format and the order in which they must be entered. disp( ± Enter the three coefficients in brackets (Highest power first).

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.

{[ snackBarMessage ]}

### Page1 / 41

M7solns4 - 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