Uploaded by Hana Bachi

HW04 4PR 5AD F18.pdf

advertisement
ME 32200 – Computer Methods in
Engineering
Homework Assignment 4
Dimitrios Fafalis, PhD
dfafalis@ccny.cuny.edu
due Sep 27, 2018 – for 4PR
due Sep 28, 2018 – for 5AD
Student’s name & ID:
Submit your files and a report with the results on Blackboard by due date.
PROBLEM 1.19. points 40 – Use MATLAB
You are working as a crime-scene investigator and must predict the temperature of a homicide
victim over a 5-hr period. You know that the room where the victim was found was at 10 ◦C
when the body was discovered.
a. Use Newton’s law of cooling (Prob. 1.14) and Euler’s method to compute the victim’s
body temperature for the 5-hr period using values of k =0.12 h−1 and ∆t =0.5 h. Assume
that the victim’s body temperature at the time of death was 37 ◦C, and that the room
temperature was at a constant value of 10 ◦C over the 5-hour period. Use Matlab to
program Euler’s method and the differential equation.
b. Further investigation reveals that the room temperature had actually dropped linearly
from 20 ◦C to 10 ◦C over the 5-hour period. Repeat the same calculation as in (a) but
incorporate this new information. (use the Matlab codes you created in (a))
c. Solve analytically for the exact solutions of (a) and (b). (Scan your solutions and upload
them with the rest of your files.)
d. Compare the results from (a), (b) and (c) by plotting them on the same graph. Use
Matlab.
e. Compute the true percent relative errors for both cases (a) and (b) according to the
equation:
[true value] − [approximate value]
ϵt =
× 100%
(1)
[true value]
where [true value] is the exact solution(s) you obtained from (c) and [approximate value]
is the approximate solutions you obtained by using Euler’s method in (a) and (b). Plot
ϵt vs t in a separate figure.
1
PROBLEM 2.7. points 20 – Use MATLAB
The“divide and average” method, an old-time method for approximating the square root of
any positive number a can be formulated as
x=
x + a/x
2
(2)
a. Write well-structured pseudocode to implement this algorithm as depicted in Fig. 1 (Fig.
P2.7 of textbook). Use proper indentation so that the structure is clear.
b. Develop, debug, and document a program to implement this equation in MATLAB. Structure your code according to Fig. P2.7 and Fig. 3.3 of your textbook.
Figure 1: Figure for problem 2.7
2
PROBLEM 4.17 and more!. points 40 – Hand-calculations and MATLAB
If |x| < 1, it is known that:
∑
1
=
xn = 1 + x + x2 + x3 + · · ·
1 − x n=0
∞
(3)
1
a. Estimate f (x) = 1−x
at x = 0.1 using eq. (3) above, showing by hand the first four
estimations for n = 0, 1, 2, 3. Compute the true percent relative error ϵt for each case
(using the true value) according to eq.(1).
b. Write a function (or script) in Matlab similar to the qseudocode for an iterative calculation
1
provided in Figure 3.3 of textbook, to compute f (x) = 1−x
at x = 0.1, according to the
right-hand side of eq. (3) for a given number of terms n. The function should return for
each iteration the approximate value of f (x) at x = 0.1, the true percent relative error
ϵt , eq.(1), and the approximate percent relative error ϵa , as given in eq.(4).
ϵa =
[current value] − [previous value]
× 100%
[current value]
(4)
The results should be stored in an array that would look like the results table of example
3.2 on page 62 of textbook. Use a stopping criterion of ϵs = 0.01%.
1
c. Expand by hand the function f (x) = 1−x
using Taylor’s series, eq. (4.7) of textbook and
express as an infinite series. Using the derived formula, estimate by hand the value of
1
f (x) = 1−x
at xn+1 = 0.1 using as previous value xn = 0.05 and the first three terms
(similar to question (a)). Compute the ϵt for each case. (Hint: see textbook examples 4.1
and 4.2).
1
using the Taylor’s series formula you
d. Develop a Matlab code to estimate f (x) = 1−x
derived in question (c). Check your code by repeating the estimate of f (x) at xn+1 = 0.2
for xn = 0.1. (you may need to modify your Matlab function).
3
Download