CS 370 Assignment 1 solution

$27.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (3 votes)

1. (10 marks)
Consider a system of floating point numbers F of our standard form
0 or ± 0.d1d2..dt × 2
p
for − 20 ≤ p ≤ 20 and d1 6= 0.
Suppose you have a number system with base 2 and that the distance between 7 and the next
largest floating point number is 2−10
.
(a) What is the distance between 70 and the next largest floating point number?
(b) What is the smallest positive normalized floating point number?
(c) What is the largest value of n such that n! can be represented exactly? Show your work.
2. ( 15 marks )
(a) Consider the recurrence sequence {pn} defined by
81pn = −81pn−1 + 10pn−2, n ≥ 2. (1)
Show that if
p0 = 1, p1 =
1
9
then
pn =

1
9
n
is an exact solution of (1) is for all n ≥ 0.
(b) Now, write a Matlab function to evaluate (1) for n = 2, . . . , 50. What happens?
(c) Carry out a stability analysis of this recursion, similar to what we did in class and explain
what you see. Note that for any two term recursion
qn + aqn−1 + bqn−2 = 0
with a, b constant, the solution is given by
qn = c1(r1)
n + c2(r2)
n
where c1, c2 are constants, and r1, r2 are roots of the equation x
2 + ax + b = 0.
3. ( 10 marks ) Suppose we have a natural spline:
S(x) =



28 + a1x + 9x
2 + x
3 x ∈ [−3, −1]
a2 + 19x + a3x
2 − x
3 x ∈ [−1, 0]
26 + 19x + 3x
2 + a4x
3 x ∈ [0, 3]
1
(a) Determine the values of a1, a2, · · ·, a4.
(b) Using the Lagrange basis, construct a cubic interpolation polynomial which interpolates
the values of S(x) at −3, −1, 0, 3.
4. ( 15 marks )
(a) Write down the linear system of equations needed to determine the derivative values
s1, s2, s3, s4, s5 for the cubic spline S(x) going through the points (1, 2), (2, 2), (4, 1),
(6, 4) and (8, 3) and having natural boundary conditions.
(b) Use the results of part (a) to determine the coefficients of S1(x), S2(x) S3(x) and S4(x)
where
S1(x) = a1 + b1(x − 1) + c1(x − 1)2 + d1(x − 1)3
1 ≤ x ≤ 2,
S2(x) = a2 + b2(x − 2) + c2(x − 2)2 + d2(x − 2)3
2 ≤ x ≤ 4,
S3(x) = a3 + b3(x − 4) + c3(x − 4)2 + d3(x − 4)3
4 ≤ x ≤ 6
S4(x) = a4 + b4(x − 6) + c4(x − 6)2 + d4(x − 6)3
6 ≤ x ≤ 8,
(2)
represent the piecewise polynomials of the cubic spline. Note that you can use Matlab
or Maple to solve the linear system if you wish.
(c) Graph this spline. That is, write a short Matlab script to produce a plot of the resulting
smooth curve over the range [1,8]. Submit the plot with your written part, and include
your code in your electronic submission.
5. ( 20 marks ) For this question, you will use MATLAB to create parametric curves representing the first letters in your first and last name, separated by an ampersand enclosed in
the outline of a hand drawn heart. Each letter should be in upper or lower case. Create
parametric curves representing the outline of an image of a heart with your first and last
initial separated by an ampersand inside the heart, written in cursive (handwriting).
For example,
Follow the steps below:
(a) Start by downloading the script file init.m from the course website, which can be modified and used to initialize data arrays for your drawing. Use Matlab’s help command
2
to learn any commands that are unfamiliar to you. Given an image, you can load it and
trace the image of the object directly using mouse clicks. To add your initials, write
them on a piece of paper, and then hold it up to the computer screen to trace it similarly.
Create your data using the mouse to select a few dozen points outlining the object and
your initials. Hitting enter once begins a new sequence of points; hitting enter twice
terminates the input. Points to note: You can modify the script as needed. The script
calls ginput for each segment (i.e., each pen stroke), and uses cell arrays to store the
data. You may also find the save and load commands useful.
(b) Using the resulting data arrays produced above, generate parametric curve representations based on smooth parametric curve interpolation as described in the course notes
(see sections 3.1 and 3.2). At least one region of the sequence should be curved enough
to be interesting (if not, you may change your initials). Show the output using piecewise
linear and cubic splines. Specifically, you will do:
Prepare three Matlab.m scripts, one for each of the following tasks (along with any functions
you choose to define). Use the same axis scaling v from init.m for subsequent plots (i.e.,
axis(v)).
(part1.m) Create a plot of the interpolation data points corresponding to the crude initial shape,
plotted with the ’∗’ symbol. The plot should have a title, and display both the axes and
gridlines.
(part2.m) Create a plot of your initials and the object created by joining the original data points
with straight lines. (The curves are not expected to look very smooth.) Include a title,
and both axis and gridlines.
(part3.m) Create two smooth plots of your initials and the object using spline interpolation, refining
the parameter partition by a factor of 5. For the first plot, use natural end conditions
and for the second plot use not-a-knot end conditions (see functions csape and fnval).
Include titles, but no gridlines or axes.
3