From d992ae8b59a850a38d08e3966e654ce054cf185e Mon Sep 17 00:00:00 2001 From: Sad-Abd Date: Fri, 10 May 2024 21:30:53 +0330 Subject: [PATCH] Added `sqrtm` to compute matrix square root --- src/matadi/math.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/matadi/math.py b/src/matadi/math.py index 7c0f180..3489c53 100644 --- a/src/matadi/math.py +++ b/src/matadi/math.py @@ -267,4 +267,17 @@ def unimodular(T): This operation preserves the isochoric (volume-preserving) part of the tensor while removing the volumetric part. """ - return (det(T) ** (-1 / 3)) * T \ No newline at end of file + return (det(T) ** (-1 / 3)) * T + +def sqrtm(C, eps = 8e-5): + """ + Compute the matrix square root of a tensor C using eigendecomposition. + """ + w = eigvals(C, eps=eps) + eye = SX.eye(3) + + M1 = (C - w[1] * eye) * (C - w[2] * eye) / (w[0] - w[1]) / (w[0] - w[2]) + M2 = (C - w[2] * eye) * (C - w[0] * eye) / (w[1] - w[2]) / (w[1] - w[0]) + M3 = (C - w[0] * eye) * (C - w[1] * eye) / (w[2] - w[0]) / (w[2] - w[1]) + + return sqrt(w[0]) * M1 + sqrt(w[1]) * M2 + sqrt(w[2]) * M3 \ No newline at end of file