29 lines
606 B
Python
29 lines
606 B
Python
#!/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):
|
||
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]
|
||
]
|
||
) |