Created
August 2, 2024 15:02
-
-
Save portnov/24bf8cb3c18a8ffca53727eff58f805a to your computer and use it in GitHub Desktop.
Decompose shear matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import numpy as np | |
def shear_xy(f1, f2): | |
m = np.eye(3) | |
m[0][2] = f1 | |
m[1][2] = f2 | |
return m | |
def shear_yz(f1, f2): | |
m = np.eye(3) | |
m[1][0] = f1 | |
m[2][0] = f2 | |
return m | |
def shear_xz(f1, f2): | |
m = np.eye(3) | |
m[0][1] = f1 | |
m[2][1] = f2 | |
return m | |
def decompose_shear(m): | |
""" | |
(%i4) sxy . syz . sxz; | |
[ f1 f4 + 1 f1 (f6 + f4 f5) + f5 f1 ] | |
[ ] | |
(%o4) [ f2 f4 + f3 f2 (f6 + f4 f5) + f3 f5 + 1 f2 ] | |
[ ] | |
[ f4 f6 + f4 f5 1 ] | |
""" | |
A = np.zeros((3,2)) | |
A[0][0] = 1 + m[2][0]*m[0][2] | |
A[0][1] = m[0][2] | |
A[1][0] = m[1][0] | |
A[1][1] = m[1][2] | |
A[2][0] = m[2][0] | |
A[2][1] = 1.0 | |
B = np.array([m[0][1], m[1][1] - 1, m[2][1]]) | |
x, res, rank, sing = np.linalg.lstsq(A, B, rcond=None) | |
f5, f6 = list(x) | |
f1 = m[0][2] | |
f2 = m[1][2] | |
f3 = m[1][0] - m[1][2]*m[2][0] | |
f4 = m[2][0] | |
sxy_ans = shear_xy(f1, f2) | |
syz_ans = shear_yz(f3, f4) | |
sxz_ans = shear_yz(f5, f6) | |
return sxy_ans, syz_ans, sxz_ans | |
if __name__ == "__main__": | |
sxy = shear_xy(0.3, 0.7) | |
syz = shear_yz(0.5, 0.4) | |
sxz = shear_xz(1.2, 0.1) | |
m = sxy @ syz @ sxz | |
sxy_ans, syz_ans, sxz_ans = decompose_shear(m) | |
print("ShearXY:") | |
print(sxy_ans) | |
print("ShearYZ:") | |
print(syz_ans) | |
print("ShearXZ:") | |
print(sxz_ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment