0% found this document useful (0 votes)
22 views

Csc349a f2023 Asn4

This document provides instructions for Assignment #4 in Computer Science 349A. It outlines requirements for submitting the assignment, including submitting questions separately in Crowdmark, not copying the assignment description, and ordering responses as specified. It also describes two potential issues - using numbers from previous years or general questions in emails rather than the discussion forum. The assignment then provides three questions to complete.

Uploaded by

milesktickner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Csc349a f2023 Asn4

This document provides instructions for Assignment #4 in Computer Science 349A. It outlines requirements for submitting the assignment, including submitting questions separately in Crowdmark, not copying the assignment description, and ordering responses as specified. It also describes two potential issues - using numbers from previous years or general questions in emails rather than the discussion forum. The assignment then provides three questions to complete.

Uploaded by

milesktickner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

COMPUTER SCIENCE 349A, FALL 2023

ASSIGNMENT #4 - 20 MARKS

DUE FRIDAY NOVEMBER 3, 2023 (11:30 p.m. PST)

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.

ˆ All assignments should be submitted electronically through the Brightspace course


website using the Crowdmark tool. Each question will be submitted separately in
Crowdmark. You may be asked to provide files for any functions (.m or .py). No other
formats will be accepted.

ˆ PLEASE DO NOT COPY THE ASSIGNMENT DESCRIPTION IN YOUR


SUBMISSION

ˆ 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

P (x) = x4 − 6x3 + 13.5x2 − 13.5x + 5.06249999


= (x − 1.5)4 − 10−8

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

Q(x) = x4 − 6x3 + 13.5x2 − 13.5x + 5.0625


= (x − 1.5)4

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:

function root = Newton( x0 , ε, imax, f , f p )


i←1
output heading
while i ≤ imax
root ← x0 − f (x0 )/f ′ (x0 )
output i, root
if |1 − x0 /root| < ε
return
end if
i←i+1
x0 ← root
end while
output “failed to converge”

2
Use the following (or similar) MATLAB print statements for output (print() statements
in Python, similarly formatted).

fprintf ( ’ iteration approximation \n’)


fprintf ( ’ %6.0f %18.8f \n’, i, root )
fprintf ( ’ failed to converge in %g iterations\n’, imax )

Note the parameters f and fp are for f and f ′ and should use the function handle
@functionname to pass the functions.

(b) (2 points) Let

√ 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:

>> x = [-7: 0.01: 5];


>> y = function_name(x);
>> plot(x,y)

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:

>> import numpy as np


>> import matplotlib.pyplot as plt
>> x = np.arange(-7,5.01,0.01)
>> y = function_name(x)
>> plt.plot(x,y)

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,

write a function with header

function p = PolyEval ( n, a, y, x )

to evaluate the polynomial

p(x) = a1 + a2 (x + y1 ) + a3 (x + y1 )(x + y2 ) + a4 (x + y1 )(x + y2 )(x + y3 ) + · · ·


· · · + an+1 (x + y1 )(x + y2 )(x + y3 ) · · · (x + yn )
n+1 j−1
X Y
= aj (x + yk )
j=1 k=1

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

a = [−1, 3.3, 0, −2.2, 5, −1.6]


y = [−1, 1, −1, 1, −1]

Include the call to the function you used to get the result.

You might also like