In this lab you will
for loops and if statements
Problem 1: Write a function x = newtonsearch(f, xguess) that finds the solution
x of the equation f(x) = 0 for an input function f and an initial guess
xguess using the Newton search algorithm.
Your Newton search algorithm should
1. Use a for loop to perform the Newton-search iteration
. Take up to ten Newton-search iterations.
2. Use an if statement inside the for loop to test if either
or
for some specified tolerance
.
3. If either of those conditions is true, use a break statement to terminate the iteration and return from the function. For our purposes
is a decent choice.
Problem 2: Test your Newton-search algorithm by solving the following problems. Check your
answers by plugging the answer x back into f and verifying that f(x) is approximately
zero.
(a) Find an
for which
.
(b) Find the cube root of 72 by devising and solving an equation of the form
whose
solution is
. Is there a simpler way to calculate
in Matlab?
Do that, and compare your answers.
(c) Find an
for which
.
Hint: find good initial guesses for the Newton search by plotting each function and roughly
estimating an
position at which
is zero.
Problem 3: Use your Newton-search algorithm to solve the following problem. Utility
companies must avoid freezing water mains in cold weather. If we assume uniform soil
conditions, the temperature
at distance
below the surface and time
after the beginning of a cold spell is given approximately by
where
is the constant surface temperature during the cold spell,
is the initial soil temperature before the cold spell started,
is the thermal conductivity of the soil, and
is the error function, computed by the built-in Matlab function erf.
If
is in meters and
is in seconds, the thermal conductivity of soil is
.
Let
and
, and recall that water freezes at
.
Use your Newton-search algorithm to determine how deep a water main must be
buried so that it will not freeze until at least 60 days' exposure to these
conditions.