[2022 Fall] Assignment6-2¶
Course: AP3021
In [1]:
Copied!
import numpy as np
import numpy as np
In [2]:
Copied!
a = np.array([[ 1, 4, 9, 16, 25],
[ 4, 9, 16, 25, 36],
[ 9, 16, 25, 36, 49],
[16, 25, 36, 49, 64],
[25, 36, 49, 64, 81]])
a_determinant = np.linalg.det(a)
print("Condition number of A:", np.linalg.cond(a, p=None))
# print('determinant of A =', a_determine)
a = np.array([[ 1, 4, 9, 16, 25],
[ 4, 9, 16, 25, 36],
[ 9, 16, 25, 36, 49],
[16, 25, 36, 49, 64],
[25, 36, 49, 64, 81]])
a_determinant = np.linalg.det(a)
print("Condition number of A:", np.linalg.cond(a, p=None))
# print('determinant of A =', a_determine)
Condition number of A: 9.915718256577622e+16
2. Repeat (a) but scale the matrix by making the max element in each row to 1.¶
In [3]:
Copied!
a = np.float32([[ 1, 4, 9, 16, 25],
[ 4, 9, 16, 25, 36],
[ 9, 16, 25, 36, 49],
[16, 25, 36, 49, 64],
[25, 36, 49, 64, 81]])
for i in range(0, 5) :
for j in range(0, 5) :
a[i][j] = float(a[i][j] / a[i][4])
# print(a[i][j])
print("Making the max element in each row to 1:\n")
print(a)
a = np.float32([[ 1, 4, 9, 16, 25],
[ 4, 9, 16, 25, 36],
[ 9, 16, 25, 36, 49],
[16, 25, 36, 49, 64],
[25, 36, 49, 64, 81]])
for i in range(0, 5) :
for j in range(0, 5) :
a[i][j] = float(a[i][j] / a[i][4])
# print(a[i][j])
print("Making the max element in each row to 1:\n")
print(a)
Making the max element in each row to 1: [[0.04 0.16 0.36 0.64 1. ] [0.11111111 0.25 0.44444445 0.6944444 1. ] [0.18367347 0.3265306 0.5102041 0.7346939 1. ] [0.25 0.390625 0.5625 0.765625 1. ] [0.30864197 0.44444445 0.60493827 0.79012346 1. ]]
3. 想想看,由condition number可知,這是一個什麼樣的矩陣呢?¶
Last update:
2024-04-27