Starting from:

$30

Assignment 1: Write a program to take 6 numbers a, b, c, d, e, f


Programming assignment 1:
Combine the write-ups for parts 1 and 2 below in a single pdf file. Upload your code
(e.g. if you used MATLAB: polyMinMax.m, nested sqrt.m, and any code you wrote
to generate the plots) as separate files in gradescope, so that we can download and
run them if needed.
Part 1: Write a program to take 6 numbers a, b, c, d, e, f and find the locations
xmin and xmax of the absolute extrema of the function
p(x) = cx3 + dx2 + ex + f
over the interval [a, b]. Use the appropriate version of the quadratic formula (which
depends on the parameters c,d,e) to avoid unnecessary cancellation of digits. Report
the extrema returned by your code for the following choices of parameters:
trial a b c d e f
1 −1 2 −1 2 −1 1
2 1 2 1 −2 −1 1
3 −2 1 4 8 −4 −2
4 −1 2 1 0 1 −3
5 −0.3 0.6 10−14 9 −3 0
6 −1 2 0 0 0 1.7
7 0 3 −3 9 −10−14 0
8 0 1 0 −2 3 −1
If you’re using MATLAB, the suggested interface is to create a file called polyMinMax.m
with first line
function rslt = polyMinMax(a,b,c,d,e,f)
where rslt is a row vector containing [xmin, xmax, p(xmin), p(xmax)]. You can then
use the driver routine part1.m in the directory Programming Assignments/prog1
on bCourses to run the cases above. In your write-up, include the output of your
code (i.e. xmin, xmax, p(xmin), p(xmax) for each case, reported to 6 digits of precision),
and plots of p(x) over [a, b] for trials 3 and 7, with markers at the extrema.
Part 2: Write a code that takes an integer, n, and returns the nth term in the
following sequence:
a1 = 1, a2 =

1 + 2, a3 =
q
1 + 2√
1 + 3, a4 =
r
1 + 2q
1 + 3√
1 + 4, . . .
The suggested interface is to create a file called nested_sqrt.m with first line
function a = nested_sqrt(n)
Evaluate an for 1 ≤ n ≤ 40. Guess the limiting value of the sequence, a = limn→∞ an,
and make a plot of ln(|an −a|) vs n. Also plot the line y = 3−(ln 2)n, treating n as a
continuous variable. From the plot, what sequence βn would you guess is appropriate
here: an − a = O(βn)?

1

More products