$29
HW3B (3.4, 3.5, 3.6 on paper, 3.7 online) Solution
3.4
8 pts
3.5
4 pts
PRETEND you are trying to computa7onally solve for the root of the equa7on f (x) = 10x −100 = 0 using the bisec7on method star7ng with the ini7al “bracket” a = 0, b = 3.
(a) Are these acceptable values for a and b? Explain. (Write out the general criteria that determine whether an ini7al a and b are acceptable for the bisec7on method, and use that to explain whether these values in par7cular are acceptable for this func7on f(x).)
(b) Calculate the values of tolX and tolf you would use for the two convergence criteria,
|xk – xk-1| < tolX and |f(xk)| < tolf , if you were to write your own bisec7on method in MATLAB.
Now (pretend) you’ve completed 33 itera7ons with the last two itera7ons having values x32 =
2.000 100000000001 and x33 = 2.000100000000000. Knowing (by inspec7on) the exact solu7on is x = 2, answer the following (and SHOW YOUR WORK!!):
(c) What is the (just plain old) error in the last itera7on (x33)?
(d) What is the “proxy” error for the last itera7on?
(e) What is the “residual” error for the last itera7on?
(f) Based on all your values above, explain whether the process has “converged” yet or not.
Use the fzero command in MATLAB to solve problem 3.3 for the weight of the hog, w, at t = 30 days. If you weren’t sure of the right f(x) = 0 equa7on to use in problem 3.3, be sure to check my solu7ons posted aZer classes Monday.
Do NOT submit your MATLAB rou7nes for this problem. But as proof you accomplished this task correctly, please write out all the following on paper:
(a) The en7re func7on (“something”.m) you needed to create for fzero to call.
(b) How you called the fzero command in your command window. It should be something like:
...something... = fzero(...something...)
(c) Your final answer for the hog weight w, in pounds, rounded to four decimals (not 4 sig. figs; I do mean 4 decimals).
3.6
4 pts
Assume the Newton-Raphson method to solve f(x) = 0 converges according to
ek+1
≈ C for
e
r
C = 0.1, and assume the error for the first itera7on is e1 = 0.1.
k
(a) Calculate the absolute value of the errors for the first 5 itera7ons
|e1| through |e5|, and plot these errors on a “convergence plot” of k vs. log10 |ek|, (by-hand, on paper).
(b) Explain by which itera7on k should the value of xk be accurate to within 8 decimals.
Remember: For every ques7on show your work! You’ll be very sad when you aren’t given credit when you write down the correct answer but don’t show me your thought process or assump7ons behind that answer.
HW3B (3.4, 3.5, 3.6 on paper, 3.7 online)
3.7
13 pts
Ever wanted to fry an egg on hot pavement? The Imagina7onTM Sta7on in Toledo says you’ve got to get the egg above 70o C to coagulate the proteins. Lets create and solve a physics-based model to see if the surface of a road can really get that hot.
Here’s a realis7c model of the heats (Q, in Wals) entering and leaving the surface of a road at (unknown) temperature T (in Celsius). You’ll learn more about this in Heat Transfer later:
• QSUN = 650 is solar heat directly hinng the pavement
at noon on a very sunny day.
• QAIR = (15) (T – 32) is the heat convected away from
the pavement by slow moving air at 32oC.
QSUN
• QSKY = (5.103 x 10-8) { (T+273)4 – (27+273)4 } is the
heat radia7ng off the pavement to the upper sky
at 27oC. The “+273” in the equa7on is conver7ng oC to Kelvin.
The temperature T (in Celsius) of the pavement is obtained when all the incoming heat balances the outgoing heat,
i.e. when QSUN = QAIR + QSKY .
Following the instruc7ons below, you’ll solve for T two ways:
TSKY = 27oC
TAIR = 32oC
QSKY QAIR
Pavement at unknown temperature T (in oC)
1. Wri7ng your own BISECTION rou7ne, which calls your own func7on pavement(T),
2. Using MATLAB’s built-in fzero func7on
and then compare how they did (and what’s easier to do!).
[A] Create the “f(x)” funcIon
First, look at the model above, and think about the func7on f(T) needed so that the solu7on to the root of f(T) = 0 gives you the desired pavement temperature T.
Hint: Since T is the solu7on to QSUN = QAIR + QSKY , then a great idea is to make f(T) = QSUN – QAIR – QSKY , where each Q has the formula above.
[B] Turn f(T) into a MATLAB funcIon
Create a func7on called pavement.m that starts with this exact line: function f = pavement(T) .
Complete the func7on so that it outputs the value of the func7on f(T) from part [A] for an input T in oC.
[C] Create a plot of f(T) over T = 0 to 100oC to help you visualize the problem. From the plot, what do you think would be a good first bracket [a, b] for the bisec7on method?
(You do not submit this plot to me – it’s just for you to see the problem before you get started.)
[D] Start with my “code fragment” (provided online) for the script HW3_7.m. Complete the code by wri7ng your own bisec7on method to converge on the solu7on for T:
• Use the given ini7al bracket of [a, b] = [0, 100] Celsius. Do not change those values please!
• Develop appropriate convergence tolerances (tolX, tolf) based on the ini7al bracket just like we discussed in class.
• Use a while loop to keep itera7ng un7l both convergence criteria are met (i.e. keep looping if either or both criteria are not met). Remember: you don’t know the “real” solu7on for temperature T yet when comparing to tolx , so use the “proxy” error |Tk – T k-1|.
• Be sure to store the value of each itera7on Tk in a vector called T_history so you can plot the method’s convergence history later.
HW3B (3.4, 3.5, 3.6 on paper, 3.7 online)
3.7 Con7nued …
• For the purposes of keeping track of the itera7ons in the “history” vector, define T1 = a and
T2 = b as the “first two” itera7ons, and then define T3 to be the first midpoint of a and b.
[E] AZer the rou7ne converges, add even more code to your HW3_7.m script to do the following:
• Run fzero with itera7ons displayed, using the same ini7al bracket [0, 100].
ˆ
, and use it to back-
• Assume this result from fzero is the “true” answer for temperature T
calculate a vector of all the “true” errors e
=
ˆ
for all the itera7ons in your Bisec7on
T −T
rou7ne you stored in the T_history vector. k
k
• Make & label a convergence history plot of your bisec7on method: plot log10(ek) as a func7on of itera7on k, up un7l convergence. Save this plot as a pdf called PLOT3_7.pdf.
That’s it! Admire how well your code did converging compared to the built-in MATLAB rou7ne. What kind of shape do you see in your “convergence history” plot? What did you think was easier (wri7ng your own code [D] or using fzero [E])? Did you ever actually fry the egg (was the pavement above 70oC)?
Finally, here’s exactly what I need you to submit ONLINE:
• Your convergence history plot PLOT3_7.pdf.
• Your two m-files: your completed, documented script HW3_7.m and func7on pavement.m.
• Enter answers to the following three ques7ons (in order) in the comment sec7on on Carmen:
a) From your Bisec7on rou7ne [D], what is the final (converged) value for temperature T to four decimals (e.g. 43.1234 oC), and how many itera7ons did it take?
ˆ
b) From the fzero rou7ne [E], what is the value of T to four decimals, and how many itera7ons
did it take?
c) Does the shape of your convergence plot (log10(error) vs. k) indicate a linear- or quadraRc-type convergence rate? Explain (briefly).
• There is nothing to submit on paper for 3.7. Only the things above in Carmen.