2023 Summer Computing Methods
Homework # 2 (100)
Problem # 1 (20)
One numerical method for calculating the cubic root of a number, √𝑃3 is in iterations. The process starts by choosing a value 𝑥1 as a first estimate of the solution. Using this value, a second, more accurate value 𝑥2 can be calculated with 𝑥2=(𝑃𝑥12+2𝑥1)/3, which is then used for calculating a third, still more accurate value 𝑥3, and so on. The general equation for calculating the value of 𝑥𝑖+1 from the val ue of 𝑥𝑖 is 𝑥𝑖+1=(𝑃𝑥𝑖2+2𝑥𝑖)/3.
Write a MATLAB program that calculates the cubic root of a number. In the program , use 𝑥1=𝑃 for the first estimate of the solution. Then, by using the general equation in a loop, calculate new, more accurate values. Stop the looping when the estimated relative error 𝜀 defined by 𝜀=|𝑥𝑖+1−𝑥𝑖 𝑥𝑖| is smaller than 0.0000 1. Use the program to calculate √17.6123, √216 .43 and √1423 .233.
Problem # 2 (20)
The Taylor series expansion for cos(x) is: cos(𝑥)=1−𝑥2 2!+𝑥4 4!−𝑥6 6!+⋯=∑(−1)𝑛 (2𝑛)!∞ 𝑛=0𝑥2𝑛 where 𝑥 is in radians. Write a MATLAB program t hat determines 𝑐𝑜𝑠 (𝑥) using the Taylor series expansion.
The program asks the user to type a value for an angle in degrees. Then the program uses a loop for adding the terms of the Taylor series. If 𝑎𝑛 is the nth term in the series, then the sum 𝑆𝑛 of the 𝑛 terms is 𝑆𝑛=𝑆𝑛−1+𝑎𝑛. In each pass calculate the estimated error 𝜀 given by 𝜀=|𝑆𝑛−𝑆𝑛−1 𝑆𝑛−1|. Stop adding terms when 𝜀≤0.000001 . The program displays the value of cos(x) . Use the program for calculating cos (35°) and cos (75°). Compare the values with those obtained by using Matlab cosd( x) function.
Problem # 3 (20)
Before calculators were readily available (about 1974), students used tables to determine the values of mathematical functions like sine, cosine, and log. Create such a table for sine, using the following steps: • Create a vector of angle values from 0 to 2 π in increments of p>10. • Calculate the sine of each of the angles, and gro up your results into a table that includes the angle and the sine. • Use disp to create a title for the table and a second disp command to create column headings. • Use the fprintf function to display the numbers. Display only two values past the decimal p oint.
Problem # 4 (20)
Biological oxygen demand (BOD) is a measure of the relative oxygen depletion effect of a waste contaminant and is widely used to assess the amount of pollution in a water source. The BOD in the effluent (Lc in mg/L) of a rock filter without recirculation is given by :
𝐿𝑐=𝐿0 1+(2.5𝐷2/3) √𝑄,
where L0 is influent BOD (mg/L), D is the depth of the filter (m), and Q is the hydraulic flow rate (Lc(m2∙day)). Assuming Q = 300 L/(m2∙day), plot the effluent BOD as a function of the depth of the filter (100 ≤ D ≤ 2000 m) for L0 = 5, 10, and 20 mg/L. Make the three plots in one figure and estimate the depth of filter required for each of these cases to obtain drinkable water. Label the axes and display a legend.
Problem # 5 (20)
The following equation describes the temperature distribution in a rectangular metal plate. The temperature on three sides is held constant at T1, and at T2 on the fourth side (see Figure ). The temperature T (x, y) as a function of the x,y coordinates shown is given by
𝑇(𝑥,𝑦)=(𝑇2−𝑇1)𝑤(𝑥,𝑦)+ 𝑇1, where 𝑤(𝑥,𝑦)= 2 𝜋∑2 𝑛∞ 𝑛 𝑜𝑑𝑑sin(𝑛𝜋𝑥 𝐿)sinh (𝑛𝜋𝑦 𝐿) sinh (𝑛𝜋𝑊 𝐿).
The given data for this problem are 𝑇1=60℃, 𝑇2=220℃, and W=L=1 m . Using a spacing of 0. 1 for both x and y, generate a surface mesh plot and a contour plot of the temperature distribution.
Bonus Problem (10)
Plot the function 𝑓(𝑥)=𝑥3−2𝑥2−10𝑠𝑖𝑛2(𝑥)−𝑒0.9𝑥 and its derivative for −4≤𝑥≤4 in one figure. Plot the function with a solid line, and the derivative with a dashed line. Add a legend and label the axes. Plot the curves with two different Matlab functions – plot and fplot , so you will have two figures.