I am studying computer science at the moment. We have the following exercise: Execute LU decomposition given a matrix A and vector b using NumPy. We had to derive L and U by hand and came up the following result:
eps = 2 ** -52
A = np.array([[1,1,1],[2,2+eps,5],[4,6,8]], dtype=np.float64)
L = np.array([[1, 0, 0], [2, 1, 0], [4, 2/eps, 1]], dtype=np.float64)
U = np.array([[1, 1, 1], [0, eps, 3], [0, 0, 4-6/eps]], dtype=np.float64)
b = np.array([1,0,0], dtype=np.float64)
Now we did tried the following code snippet to find the vector x using L and U and also finding x (x_dir) using the original A matrix and b vector. The only problem: one other student and I have a different result for x:
import numpy as np
eps = 2**-52
A = np.array([[1,1,1],[2,2+eps,5],[4,6,8]], dtype=np.float64)
L = np.array([[1, 0 ,0], [2, 1, 0], [4, 2/eps ,1]], dtype=np.float64)
U = np.array([[1,1,1],[0,eps,3],[0,0, 4-(6/eps)]], dtype=np.float64)
b = np.array([1,0,0], dtype=np.float64)
y = np.linalg.solve(L, b.T)
'''Ly=b'''
print(y)
'''Ux=y'''
x = np.linalg.solve(U, y)
print(x)
x_dir = np.linalg.solve(A,b.T)
print(x_dir)
The result on my computer and the one of a fellow student for x (using LU) was:
[ 3.66666667 -2. -0.66666667]
But, the result for this calculation was meant to be:
[2.66666667 -1. −0.66666667]
Only he and I have this problem.
We already tried reinstalling NumPy, using different versions of it, using it in venv's and actual virtual machines. We sent the same code snippet to other students and they get the wished result.
What are possible causes for this problem? Based on our knowledge and the given situation we believe it has something to do with the used CPUs or our computers.
- His CPU: AMD RYZEN 7 5825 U with Radeon graphics
- My CPU: 12th Gen Intel(R) Core(TM) i7-12700H
Does anyone have any ideas, suggestions what the cause of this problem could be or has encountered similar problems?