- 2 Matrices 10 Marks Consider The Computer Code Below Left Python Right Matlab And In Particular The Algorithm H 1 (92.46 KiB) Viewed 33 times
2. Matrices [10 marks] Consider the computer code below (left, Python; right, MATLAB), and in particular the algorithm h
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
2. Matrices [10 marks] Consider the computer code below (left, Python; right, MATLAB), and in particular the algorithm h
2. Matrices [10 marks] Consider the computer code below (left, Python; right, MATLAB), and in particular the algorithm highlighted inside the black dashed lines between Lines 8 and 15. 1 import numpy as np 3 def Method(): function Method 3 4 5 6 A=np.array([[1,2,5), (3,2,1], [2,4,1]]) x-np.array([1,0,0]).T A=[1 2 5; 3 2 1: 2 4 1]; x=[100]'; for i in range (5): xl = np.dot (A,x) 9 xl = xl/np. sqrt (np.dot (x1.T,xl)) 10 num = np.dot (x1.T, np.dot (A, xl)) 11 denom = np.dot (x1.T,xl) 12 a = num/denom 13 Xxl 14 15 print (x, a) for i=1:5 xl - A*x; xl = xl/sqrt(xl'*xl); num - xl'* (A*xl): denomxl'*xl; a = num/denom; Xxl; end (x, a) (a) What is the name of the algorithm or method being implemented? [2 marks] (b) What are the quantities x and a, printed on line 16, estimates of? [2 marks] (c) Briefly explain the changes you would make to this code to improve the accuracy of the estimates described in (b). [2 marks] (d) Identify an inefficiency of this algorithm and state which line of the code could be safely deleted. [2 marks] (e) How could you check whether the algorithm has been correctly implemented? [2 marks]