This repository has been archived on 2020-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
tpmni/5/code.py

29 lines
606 B
Python
Raw Permalink Normal View History

2020-02-10 08:54:30 +01:00
#!/usr/bin/env python
import numpy as np
from copy import deepcopy as dp
"""
TP final MNI
auteurs: Cyril Colin
Dylan Voisin
date: 10/02/2020
"""
def gradient_conjugué(A: np.ndarray, b: np.ndarray, nb=50):
2020-02-10 08:54:30 +01:00
p = dp(b)
r = dp(b)
x = np.zeroes(b.shape)
for i in range(nb):
α = (r.transpose() @ r) / (p.transpose() @ A @ p)
x = x + α @ p
r = r - α @ A @ p
β = (r.transpose() @ r) / (r.transpose() @ r)
p = r + β @ p
return x
if __name__ == '__main__':
A = np.array(
[
[2, 3, 4]
]
)