Normas#
import numpy as np
import numpy.linalg as la
x = np.random.randint(10, size=(5, 5))
x
array([[4, 4, 6, 3, 9],
[0, 9, 8, 1, 8],
[9, 6, 6, 7, 9],
[0, 0, 3, 7, 4],
[6, 8, 9, 0, 4]])
la.norm(x)
30.364452901377952
la.norm(x=x, ord=np.inf)
37.0
np.sum(a=x, axis=1) # por filas
array([26, 26, 37, 14, 27])
np.sum(x[-1, :]) # Primera fila
27
la.norm(x=x, ord=-np.inf)
14.0
A = np.random.randint(10, size=(5, 5))
dA = np.random.random(size=(5, 5)) * 1e-2
A
array([[2, 7, 6, 3, 8],
[8, 1, 3, 6, 1],
[2, 6, 1, 5, 5],
[3, 9, 4, 5, 4],
[3, 8, 5, 0, 9]])
dA
array([[1.94124179e-03, 9.23888470e-03, 2.62745731e-03, 1.50224370e-03,
8.85435469e-06],
[8.25181745e-03, 3.38225574e-03, 1.90457534e-03, 6.35744944e-04,
9.66298323e-03],
[3.14087161e-03, 3.06781757e-03, 9.56458574e-03, 2.73470562e-03,
7.93938146e-03],
[3.95234892e-03, 6.09382071e-03, 8.92778119e-03, 4.17657127e-03,
9.18758691e-03],
[7.64912670e-03, 7.60160904e-03, 7.74530024e-03, 6.88571667e-03,
4.28865041e-03]])
A + dA
array([[2.00194124e+00, 7.00923888e+00, 6.00262746e+00, 3.00150224e+00,
8.00000885e+00],
[8.00825182e+00, 1.00338226e+00, 3.00190458e+00, 6.00063574e+00,
1.00966298e+00],
[2.00314087e+00, 6.00306782e+00, 1.00956459e+00, 5.00273471e+00,
5.00793938e+00],
[3.00395235e+00, 9.00609382e+00, 4.00892778e+00, 5.00417657e+00,
4.00918759e+00],
[3.00764913e+00, 8.00760161e+00, 5.00774530e+00, 6.88571667e-03,
9.00428865e+00]])
b = np.random.randint(10, size=5)
db = np.random.random(size=5) * 1e-2
b = b.reshape(5, 1)
db
array([0.00881303, 0.00460518, 0.00232491, 0.0094839 , 0.00863815])
b + db
array([[4.00881303, 4.00460518, 4.00232491, 4.0094839 , 4.00863815],
[6.00881303, 6.00460518, 6.00232491, 6.0094839 , 6.00863815],
[5.00881303, 5.00460518, 5.00232491, 5.0094839 , 5.00863815],
[8.00881303, 8.00460518, 8.00232491, 8.0094839 , 8.00863815],
[3.00881303, 3.00460518, 3.00232491, 3.0094839 , 3.00863815]])
np.concatenate((A, b), axis=1 # matriz aumentada
Cell In[17], line 1
np.concatenate((A, b), axis=1 # matriz aumentada
^
SyntaxError: incomplete input
A.shape
(5, 5)
b.shape
(5, 1)
b
array([[3],
[3],
[6],
[8],
[3]])
la.cond(A)
60.930772057178615
la.cond(A + dA)
60.21344278652582
\[
\frac{\|\Delta \mathbf{x}\|}{\|\mathbf{x}+\Delta \mathbf{x}\|} \leq\|\mathbf{A}\|\left\|\mathbf{A}^{-1}\right\| \frac{\|\Delta \mathbf{A}\|}{\|\mathbf{A}\|}
\]
la.norm(db) / la.norm(b + db)
0.00044789747999778414
la.norm(A) * la.norm(la.inv(A)) * la.norm(dA) / la.norm(A)
0.07290285213747842
M = np.zeros((8, 8))
M + 0.1
array([[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]])