You are on page 1of 7

# 13

9974949866 0.8) year future worth 0 100000. y = [nn.00000003 8 0.tru.9974949866 0.2f\n'. fprintf('order true value approximation error\n'). i.90 5 146932.37669564 2 0.81 6 158687.er).00 2 116640.00021414 6 0. F = P*(1+i).00000310 7 0.9974949866 0.43 8 185093.i.1 The M-file can be written as function sincomp(x.2 The M-file can be written as function futureworth(P.1) * x^(2*i-1) / factorial(2*i-1). fprintf('%5d %14.9973911830 0. fprintf('\n year future worth\n').0. i = i + 1.02 14 . n) nn = 0:n.9974949866 0.5.08. end ser = ser + (-1)^(i .8) order true value approximation error 1 0.9974971226 -0. break.0007812500 -0.n) i = 1.CHAPTER 3 3.9974949866 1.9974949869 -0. >> futureworth(100000.00000000 3.9974949557 0. This function can be used to evaluate the test case.01040643 5 0.00 3 125971.01456523 3 0.32945162 4 0. fprintf('%3d %14.^nn. er = (tru .10f %14.9375000000 6. tru = sin(x). end This function can be used to evaluate the test case.5000000000 -50.ser.9974949866 0.00 1 108000.9974949866 0.ser) / tru * 100.8f\n'. ser = 0. while (1) if i > n.F].y).43 7 171382. fprintf('\n').20 4 136048.9974949866 0.9974949866 1. >> sincomp(1.10f %12.

Tpeak.5 The M-file can be written as function vol = tankvol(R.30 5 8673.y).1.8418 >> avgtemp(23. >> avgtemp(5.2.76 3. 15 . fprintf('%5d %14.1..076. fprintf('\n year annualpayment\n').0398 3./((1+i). Tavg = mean(Te).^nn. Te = Tmean + (Tpeak-Tmean)*cos(omega*(t-205)). elseif d <= 3 * R v1 = pi * R ^ 3 / 3.0.4 The M-file can be written as function Tavg = avgtemp(Tmean.5) year annualpayment 1 37660.2f\n'.A].26 4 10473.242) ans = 33. t = tstart:tend. i. v2 = pi * R ^ 2 * (d .59) ans = -10. tstart.^nn-1). This function can be used to evaluate the test case. tend) omega = 2*pi/365. >> annualpayment(35000. d) if d < R vol = pi * d ^ 3 / 3.3 The M-file can be written as function annualpayment(P.3.00 2 19519.180.33. This function can be used to evaluate the test cases. y = [nn. else error('overtop') end This function can be used to evaluate the test cases. n) nn = 1:n.R). vol = v1 + v2.22.34 3 13483. A = P*i*(1+i).6.

elseif y < 0 th = atan(y / x) .1) ??? Error using ==> tankvol overtop 3. end else if y > 0 th = pi / 2.3304 >> tankvol(1.5) ans = 0.0.1309 >> tankvol(1.6755 >> tankvol(1.3. for the first case.pi.th]=polar(1. y) r = sqrt(x . th] = polar(x. >> tankvol(1.1. if x < 0 if y > 0 th = atan(y / x) + pi.^ 2). else th = 0.6 The M-file can be written as function [r.^ 2 + y .0) ans = 7. end end th = th * 180 / pi. else th = pi. For example.3.2) ans = 1.1) r = 1. elseif y < 0 th = -pi / 2. >> [r. This function can be used to evaluate the test cases.4142 th = 90 The remaining cases are 16 .

ou). n = length(x).pi.0000 -1. >> polar2(x.2f %8.4142 -135.4142 90 1 −1 1.^ 2 + y .4142 -90.0000 0. fprintf('\n x y radius angle\n'). This function can be used to evaluate the test cases and display the results in tabular form. else th(i) = 0.4f\n'.0000 -90.y) x y radius angle 1.00 1.4142 −135 −1 0 1. y) r = sqrt(x .00 -1. end end th(i) = th(i) * 180 / pi.0000 -1.00 0.4142 −90 1 0 1.00 -1. elseif y(i) < 0 th(i) = -pi / 2.0000 0 3.00 1.00 1. fprintf('%8.0000 180 0 1 1.0000 0.00 1.0000 90.r.0000 0 −1 1 1.7 The M-file can be written as function polar2(x. end else if y(i) > 0 th(i) = pi / 2.00 0.00 1.0000 0. end ou = [x.00 1.0000 0. elseif y(i) < 0 th(i) = atan(y(i) / x(i)) .0000 -1.0000 0.4142 135 −1 −1 1.th].0000 1. x y r θ 1 1 1.^ 2).0000 17 .y.00 -1. else th(i) = pi.00 1.0000 180.4142 135.00 0.00 1. for i = 1:n if x(i) < 0 if y(i) > 0 th(i) = atan(y(i) / x(i)) + pi.0000 90 0 −1 1.00 0.0000 −90 0 0 0.0000 1.2f %10.4142 90.00 1.00 1.4f %10.00 1.

3624 0. >> lettergrade(95) ans = A >> lettergrade(45) ans = F >> lettergrade(80) ans = B 3.50 1.5167 0./(A(:.020 0.5) = sqrt(A(:.0007 24.6094 0.5809 0.035 0.022 0.^(2/3).8 The M-file can be written as function grade = lettergrade(score) if score >= 90 grade = 'A'.A').00 0.00 3. fprintf('%8. end This function can be tested with a few cases.*(A(:.00 1.9 The M-file can be written as function Manning(A) A(:.*A(:.3f %8.015 0. elseif score >= 70 grade = 'C'. This function can be run to create the table.50 2.00 2./A(:.3.030 0. fprintf('\n n S B H U\n').1).0010 20.3)+2*A(:.00 1. elseif score >= 60 grade = 'D'.4))).1971 18 .0003 15.4f\n'.4f %10.4).00 0.0002 8.2)). >> Manning(A) n S B H U 0.2f %10. elseif score >= 80 grade = 'B'.2f %10.00 2.3).0001 10. else grade = 'F'.00 1.

end plot(xx. for i=1:n uy(i) = -5/6. uy(i) = uy(i) + 15/6.238.0. plot(h. V) This function can be run to the plot.5. else s=0.^2))*L.x).*sqrt(2*r*h-h.*sing(xx(i).*xx(i).4)). end This function can be run to create the plot.7./r)-(r-h).8.4)-sing(xx(i).10 The M-file can be written as function beam(x) xx = linspace(0.uy) function s = sing(xxx.3.a.*xx(i)^3 .a).2). uy(i) = uy(i) + 57/6. V = (r^2*acos((r-h).3) + 75*sing(xx(i). n=length(xx).25. >> cylinder(2.5) 19 .2*r). >> beam(10) 3.^n.n) if xxx > a s = (xxx . L) h = linspace(0.11 The M-file can be written as function cylinder(r.*(sing(xx(i).