Economic formulas are available to compute annual

up to the order term of your choosing. For each of the pre- ceding, compute and display the percent relative error as error = true − series approximation true × 100 As a test case, employ the program to compute sin0.9 for up to and including eight terms—that is, up to the term x 15 15.

3.6 Two distances are required to specify the location of a

point relative to an origin in two-dimensional space Fig. P3.6: • The horizontal and vertical distances x, y in Cartesian coordinates. • The radius and angle r, θ in polar coordinates. It is relatively straightforward to compute Cartesian coordi- nates x, y on the basis of polar coordinates r, θ . The reverse process is not so simple. The radius can be computed by the following formula: r = x 2 + y 2 If the coordinates lie within the first and fourth coordi- nates i.e., x 0, then a simple formula can be used to compute θ : θ = tan −1 y x The difficulty arises for the other cases. The following table summarizes the possibilities: x y θ tan −1 yx + π tan −1 yx − π =0 π =0 π 2 =0 −π2 =0 =0 Write a well-structured M-file using if...elseif struc- tures to calculate r and θ as a function of x and y. Express the final results for θ in degrees. Test your program by evaluat- ing the following cases: x y r θ 2 2 1 3 −3 1 −2 −1 −2 −2 2 2

3.7 Develop an M-file to determine polar coordinates as

described in Prob. 3.6. However, rather than designing the function to evaluate a single case, pass vectors of x and y. Have the function display the results as a table with columns for x, y, r, and θ . Test the program for the cases outlined in Prob. 3.6.

3.8 Develop an M-file function that is passed a numeric

grade from 0 to 100 and returns a letter grade according to the scheme: Letter Criteria A 90 ≤ numeric grade ≤ 100 B 80 ≤ numeric grade 90 C 70 ≤ numeric grade 80 D 60 ≤ numeric grade 70 F numeric grade 60 The first line of the function should be function grade = lettergradescore FIGURE P3.6 y x ␪ I II III IV r Design the function so that it displays an error message and terminates in the event that the user enters a value of score that is less than zero or greater than 100. Test your function with 89.9999, 90, 45 and 120.

3.9 Manning’s equation can be used to compute the velocity

of water in a rectangular open channel: U = √ S n B H B + 2H 23 where U = velocity ms, S = channel slope, n = roughness coefficient, B = width m, and H = depth m. The follow- ing data are available for five channels: n S B H 0.036 0.0001 10 2 0.020 0.0002 8 1 0.015 0.0012 20 1.5 0.030 0.0007 25 3 0.022 0.0003 15 2.6 Write an M-file that computes the velocity for each of these channels. Enter these values into a matrix where each col- umn represents a parameter and each row represents a chan- nel. Have the M-file display the input data along with the computed velocity in tabular form where velocity is the fifth column. Include headings on the table to label the columns. 3.10 A simply supported beam is loaded as shown in Fig. P3.10. Using singularity functions, the displacement along the beam can be expressed by the equation: u y x = −5 6 [x − 0 4 − x − 5 4 ] + 15 6 x − 8 3 + 75x − 7 2 + 57 6 x 3 − 238.25x PROBLEMS 85 By definition, the singularity function can be expressed as follows: x − a n = x − a n when x a when x ≤ a Develop an M-file that creates a plot of displacement dashed line versus distance along the beam, x. Note that x = 0 at the left end of the beam.

3.11 The volume V of liquid in a hollow horizontal cylinder of

radius r and length L is related to the depth of the liquid h by V = r 2 cos −1 r − h r − r − h 2r h − h 2 L Develop an M-file to create a plot of volume versus depth. Here are the first few lines: function cylinderr, L, plot_title volume of horizontal cylinder inputs: r = radius L = length plot_title = string holding plot title Test your program with cylinder3,5,... Volume versus depth for horizontal... cylindrical tank

3.12 Develop a vectorized version of the following code:

tstart=0; tend=20; ni=8; t1=tstart; y1=12 + 6cos2pit1tend-tstart; for i=2:ni+1 ti=ti-1+tend-tstartni; yi=10 + 5cos2piti ... tend-tstart; end 20 kipsft 150 kip-ft 15 kips 5’ 2’ 1’ 2’ FIGURE P3.10