This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
NumericalAnalysisModule/3 - Splines/source/residue.py

40 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
import numpy as np
from scipy.linalg import solve
from numpy.linalg import norm
# Matriz construída pelo programa em C++
A = np.matrix([[1, 0, 0, 0, 0, 0],
[0.166667, 0.666667, 0.166667, 0, 0, 0],
[0, 0.166667, 0.5, 0.0833333, 0, 0],
[0, 0, 0.0833333, 0.333333, 0.0833333, 0],
[0, 0, 0, 0.0833333, 0.5, 0.166667],
[0, 0, 0, 0, 0, 1]])
b = np.array([0, 1.2, -1.2, 0.8, 0.4, 0])
x2 = np.array([0, 2.76846, -3.87386, 3.30622, 0.248963, 0])
x = solve(A, b)
print(norm(x - x2))
A = np.matrix([[1, 0, 0, 0, 0, 0, 0, 0, 0],
[0.0416667, 0.166667, 0.0416667, 0, 0, 0, 0, 0, 0],
[0, 0.0416667, 0.166667, 0.0416667, 0, 0, 0, 0, 0],
[0, 0, 0.0416667, 0.166667, 0.0416667, 0, 0, 0, 0],
[0, 0, 0, 0.0416667, 0.166667, 0.0416667, 0, 0, 0],
[0, 0, 0, 0, 0.0416667, 0.166667, 0.0416667, 0, 0],
[0, 0, 0, 0, 0, 0.0416667, 0.166667, 0.0416667, 0],
[0, 0, 0, 0, 0, 0, 0.0416667, 0.166667, 0.0416667],
[0, 0, 0, 0, 0, 0, 0, 0, 1]])
b = np.array([0, 7.862, -10.7327, 12.1347, 2, -8.13471, 14.7327, -3.862, 0])
x2 = np.array([0, 73.9996, -107.31, 97.6564, 7.91753, -81.3265, 122.156, -53.7109, 0])
x = solve(A, b)
print(norm(x - x2))