Csc349a f2023 Asn4
Csc349a f2023 Asn4
ASSIGNMENT #4 - 20 MARKS
This is a really large class and the logistics of grading assignments are challenging. Me
and the markers require your help in making this process go smoothly. Please ensure that
your assignments conform to the following requirements - any violation will result in getting
a zero for the particular assignment.
The answers to the questions should be in the same order as in the assignment speci-
fication.
Some of the questions of the assignments are recycled from previous years but typically
with small changes in either the description or the numbers. Any submission that
contains numbers from previous years in any questions will be immediately graded
with zero.
Any general assignment related questions can be posted in the Discussion Forum in
Brightspace for the assignment.
Any specific assignment related questions (details about your solution) should be e-
mailed ([email protected]) to me and have a subject line of the form CSC349A Assignment
X, where X is the number of the corresponding assignment.
1
Question #1 - 6 Marks
(a) (2 points) Compute exactly (using algebra) the four roots of the polynomial equation
P (x) = 0, where
This can be most easily done by noting that P (x) = 0 implies that (x − 1.5)4 = 10−8 .
This polynomial equation has 2 real roots and 2 complex conjugate roots.
(b) (2 points) Consider the perturbed polynomial
which is obtained by perturbing one coefficient of P (x) by 10−8 . What is the relative
change in the coefficient 5.06249999, from P (x) to Q(x)? In Q(x) = 0, all four roots
are equal to 1.5, what is the relative change in the largest root from (a) with respect
to the given perturbation?
(c) (2 points) From the above, what can you conclude about the condition of the problem
of computing the roots of the equation P (x) = 0?
Question #2 - 8 Marks
For this question your are going to create a function in MATLAB or Python for approximat-
ing a root of a function using the Newton-Raphson method. You will then use your Newton
function to solve an engineering problem from the textbook.
(a) (2 points) Write a function for Newton’s method corresponding to the following pseu-
docode:
2
Use the following (or similar) MATLAB print statements for output (print() statements
in Python, similarly formatted).
Note the parameters f and fp are for f and f ′ and should use the function handle
@functionname to pass the functions.
√ x2 √
f (x) = cos (x + 2) + + 2x
2
and use your function in (a) to approximate a zero of f (x) with x0 = 1, ε = 10−6 ,
and imax = 50. You will need to create MATLAB (or Python) functions for f (x) and
f ′ (x), to pass as arguments to Newton.
(c) (2 points) Let xa denote your approximate root found in part (b) and calculate f (x√ a ),
f ′ (xa ), and the relative error of your approximation where the true root is xt = − 2
in MATLAB (or Python). Note, your approximation should only have 4 significant
figures which, given the precision of MATLAB or Python, is not great.
(d) (2 points) Plot the graph of the function f (x) from (b) on interval [-7, 5].
This can be done by entering the following MATLAB commands:
This will cause a graphics window to open, and you can print the graph. You should
be able to tell by looking at this graph why the approximation in (c) is good but not
great.
In Python I used the following commands:
Question #3 - 6 Marks.
3
(a) (4 points) Given input consisting of
a positive integer n,
a vector a with n + 1 entries a1 , a2 , . . . , an+1 ,
a vector y with n entries y1 , y2 , . . . , yn , and
a scalar x,
function p = PolyEval ( n, a, y, x )
using Horner’s algorithm. Note. Your function should use exactly 3n flops (floating-
point operations).
(b) (2 points) Use your function from (a) to evaluate p(1.53) when n = 5 and
Include the call to the function you used to get the result.