python09(): Exercises for linear algebra. x = [1 2 3] type(x) = x.shape = (3,) len(x) = 3 x = [1 2 3] x.T = [1 2 3] np.transpose(x) = [1 2 3] r = [[1 2 3]] type(r) = r.shape = (1, 3) len(r) = 1 r.T = [[1] [2] [3]] c = [[1] [2] [3]] type(c) = c.shape = (3, 1) len(c) = 3 c.T = [[1 2 3]] 2-norm and max-norms of vectors: 2Norm of [0.58059087 0.55830806] is 0.8054772771622787 MNorm of [0.58059087 0.55830806] is 0.5805908708937461 2Norm of [3 4] is 5.0 MNorm of [3 4] is 4.0 2Norm of [1. 1.] is 1.4142135623730951 MNorm of [1. 1.] is 1.0 Magnitude and direction of a vector: v: [2 3] ||v|| = np.linalg.norm(v) = 3.605551275463989 vhat = v / ||v||: [0.5547002 0.83205029] v2 = ||v|| * vhat: [2. 3.] w = 10 * v [20 30] ||w|| = np.linalg.norm(w) = 36.05551275463989 what = w / ||w||: [0.5547002 0.83205029] dot product of w and x: np.dot(w,x) w = np.random.rand ( 2 ) [0.94984462 0.43526836] x = np.random.rand ( 2 ) [0.23238047 0.78150679] np.dot(w,x) = 0.5608905249145545 Cosine of angle between w and x: w dot x / ||w|| / ||x|| ||w|| = 1.0448269498399188 ||x|| = 0.8153241999651156 cos(w,x) = 0.658420591366336 angle = 0.8520779601800194 radians, 48.82047093443133 degrees norm(x) = sqrt(x dot x ) norm ( x ) = 0.8153241999651156 sqrt(dot(x,x)) = 0.8153241999651156 projection of v onto u u: [3 4] uhat: [0.6 0.8] v: [5 1] beta = np.dot ( v, uhat ) = 3.8 v1: [2.28 3.04] v2: [ 2.72 -2.04] angle (v1,uhat) = 0.0 = 0.0 degrees angle (v2,uhat) = 1.5707963267948966 = 90.0 degrees Matrix A: [[11 12 13 14] [21 22 23 24] [31 32 33 34]] type(A) = A.shape = (3, 4) len(A) = 3 A.T: [[11 21 31] [12 22 32] [13 23 33] [14 24 34]] Matrix norms: np.linalg.norm(A) = 83.00602387778854 np.linalg.norm(A,1) = 72.0 np.linalg.norm(A,2) = 82.99552942749328 np.linalg.norm(A,np.inf) = 130.0 np.linalg.norm(A,'fro') = 83.00602387778854 Matrix-vector multiplication: A*x=y A [[1 2 3] [4 5 6] [7 8 0]] x [1 2 3] y = np.matmul(A,x) = A*x: [14 32 23] Given A, y, solve A*x=y for x A [[1 2 3] [4 5 6] [7 8 0]] y [14 32 23] x = np.linalg.solve(A,y) [1. 2. 3.] Verify by computing A*x: [14. 32. 23.] Estimate matrix norm ||A|| = max ||Ax|| / ||x|| A_norm = 13.201458618948678 A_norm_estimate = 13.193701316232195