Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Only answer c and d thanks 10 marks Question 2 The banded, upper triangular matrix Ae Rnxn can be written as [a bici 02b2 C2

Only answer c and d thanks

image text in transcribed

10 marks Question 2 The banded, upper triangular matrix Ae Rnxn can be written as [a bici 02b2 C2 A = . .. an- bn-2 an-1 Cn-2 bn-1 where = (a1, 22, ...,An-2, an-1, an) ER", b= (b1,b2, ..., bn-2, bn-1) ER-1, = (C1,C2, ..., 6n-2) ER-2 The entries of a, b, and are all assumed to be nonzero. (a) Write a pseudocode for computing the matrix-vector product of A with a vector r. That is, given vectors a, b, and that define A as in definition (1), and given a vector 2 ER", your algorithm should compute the matrix-vector product y = Ar without forming an nxn array. Your pseudocode should have the following form: Input: vector TER" and vectors a ER", DER"-1 and CER"-2. Insert pseudocode here Output: vector y en such that y = Az (b) Analyse the complexity of the algorithm from part (a). That is, determine how many flops are required to compute the product y = AF with your algorithm. In terms of "Big-Oh" notation, what is the asymptotic behaviour of your algorithm as n increases? (c) Implement your pseudo-code in as a function called tridag_matvec.py. Also, write a script called compare.py to generate a tridiagonal test matrix and a test vector for a n = 10 , k = 2, ...,7, compute the product and measure the time your code takes to complete. Produce a plot of the time taken versus n on a logarithmic scale, along with your prediction. (d) (5 bonus marks) Repeat the test, but now using the built-in matrix-vector product (@/scipy.dot/scipy.matmul) and the matrix A defined as an nxn matrix with mostly zeros. Plot the time taken in the same plot as for (c). Which algorithm is faster? Is the difference as great as you expected? 10 marks Question 2 The banded, upper triangular matrix Ae Rnxn can be written as [a bici 02b2 C2 A = . .. an- bn-2 an-1 Cn-2 bn-1 where = (a1, 22, ...,An-2, an-1, an) ER", b= (b1,b2, ..., bn-2, bn-1) ER-1, = (C1,C2, ..., 6n-2) ER-2 The entries of a, b, and are all assumed to be nonzero. (a) Write a pseudocode for computing the matrix-vector product of A with a vector r. That is, given vectors a, b, and that define A as in definition (1), and given a vector 2 ER", your algorithm should compute the matrix-vector product y = Ar without forming an nxn array. Your pseudocode should have the following form: Input: vector TER" and vectors a ER", DER"-1 and CER"-2. Insert pseudocode here Output: vector y en such that y = Az (b) Analyse the complexity of the algorithm from part (a). That is, determine how many flops are required to compute the product y = AF with your algorithm. In terms of "Big-Oh" notation, what is the asymptotic behaviour of your algorithm as n increases? (c) Implement your pseudo-code in as a function called tridag_matvec.py. Also, write a script called compare.py to generate a tridiagonal test matrix and a test vector for a n = 10 , k = 2, ...,7, compute the product and measure the time your code takes to complete. Produce a plot of the time taken versus n on a logarithmic scale, along with your prediction. (d) (5 bonus marks) Repeat the test, but now using the built-in matrix-vector product (@/scipy.dot/scipy.matmul) and the matrix A defined as an nxn matrix with mostly zeros. Plot the time taken in the same plot as for (c). Which algorithm is faster? Is the difference as great as you expected

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions