import numpy as np
A = np.array([[3, 2, 1], [5, 7, 4], [9, 6, 8]]); print(A);
B = np.transpose(A); print(B);
C = A.T; print(C);
print(np.allclose(B, C)); # To check whether all the elements of B are equal to C.
print(A);
d = np.linalg.det(A);
print(d);
A = np.random.randint(1, 10, size=(3,3));
B = np.random.randint(1, 10, size=(3,3));
C = np.dot(A, B); # Matrix multiplication
d = np.linalg.det(C);
e = np.linalg.det(A)*np.linalg.det(B);
print("LHS:%3.16f\n"%d);
print("RHS:%3.16f\b"%e);
print(np.isclose(d, e, rtol=1e-5));
print("Relerr:%3.16f"%(np.abs(1-d/e)));
print(A);
a = np.linalg.det(A); print(a);
B = np.linalg.inv(A); print(B);
C = np.dot(A, B); print(np.round(C,1));
lhs = np.transpose(np.linalg.inv(A));
rhs = np.linalg.inv(np.transpose(A));
print(lhs);
print(rhs);
print(np.allclose(lhs, rhs))
A = np.random.randint(1, 10, size=(3,3));
B = np.random.randint(1, 10, size=(3,3));
C = np.dot(A,B); D = np.dot(B, A);
print(C); print(D);
print(np.allclose(C, D));
def check_symm(aditya):
return(np.allclose(aditya, aditya.T));
A = np.array([[1, 2, 3], [2, 4, 5], [3, 5, 6]]); print(A);
print(check_symm(A));
print(A); print(B);
c = np.tensordot(A, B); print(c);
s = 0;
for i in np.arange(0,3):
for j in np.arange(0,3):
s = s + A[i, j]*B[i, j];
print(s)
# A vectorized way of computing the tensordot product
C = np.sum(np.ndarray.flatten(A)*np.ndarray.flatten(B))
print(C)
$\mathbf{v}'= \mathbf{Q}\cdot \mathbf{v}$, here $\textbf{Q}$ is the transformation matrix
We specify the angle of rotation as $\theta$ and then declare the transformation matrix $\textbf{Q}$ based on that
theta = 30*np.pi/180;
Q = np.array([[np.cos(theta), np.sin(theta)], [-np.sin(theta), np.cos(theta)]]);
print(Q)
c = np.linalg.det(Q); print(c);
lhs = np.transpose(Q);
rhs = np.linalg.inv(Q);
print(np.allclose(lhs, rhs, rtol=1e-6))
I = np.eye(2); print(I);
print(np.allclose(np.dot(Q, Q.T), I));
a = np.array([1, 3])
ap = np.dot(Q, a);
print(ap)
# vary Theta from 0 to 2pi radians
theta_a = np.linspace(0, 2*np.pi, 100); # Theta in radians
# Elements of vector in initial frame: theta = 0
a = np.array([1,3]);
# Generate a matrix to store the transformed elements for correspoding theta
ap1_a = np.zeros(np.shape(theta_a));
ap2_a = np.zeros(np.shape(theta_a));
# Iterate over theta values and assign the values to ap1_a and ap2_a
count = 0;
for theta in theta_a:
Q = np.array([[np.cos(theta), np.sin(theta)], [-np.sin(theta), np.cos(theta)]]);
ap = np.dot(Q, a);
ap1_a[count] = ap[0]; # 1st element, index = 0
ap2_a[count] = ap[1]; # 2nd element, index = 1
count = count + 1;
import matplotlib.pyplot as plt
plt.rcParams.update({"text.usetex":True})
%config InlineBackend.figure_format='svg';
plt.plot(theta_a, ap1_a, label="$a'_1$");
plt.plot(theta_a, ap2_a, label="$a'_2$");
plt.grid(True);
plt.xlabel("$\\theta$");
plt.ylabel("Components of a'");
plt.legend();
plt.plot(ap1_a, ap2_a);
ax = plt.gca();
ax.set_aspect(1);
plt.plot(a[0], a[1], 'ok'); # initial vector
theta = 30*np.pi/180;
Q = np.array([[np.cos(theta), np.sin(theta)], [-np.sin(theta), np.cos(theta)]]);
# Original state of stress
s = np.array([[50, 30], [30, -20]]);
print(s);
# Transformed matrix
sp = np.dot(np.dot(Q,s), Q.T);
print(sp);
theta_a = np.linspace(0, np.pi, 100); # Theta in radians
sigma_n_a = np.zeros(np.shape(theta_a));
tau_n_a = np.zeros(np.shape(theta_a));
count =0;
for theta in theta_a:
Q = np.array([[np.cos(theta), np.sin(theta)], [-np.sin(theta), np.cos(theta)]]);
s = np.array([[50, 30], [30, -20]]);
sp = np.dot(np.dot(Q,s), Q.T);
sigma_n_a[count] = sp[0,0];
tau_n_a[count] = sp[0,1];
count+=1; # count = count + 1
plt.plot(sigma_n_a, tau_n_a);
plt.plot(np.trace(s)/2, 0, 'ok'); # center of the circle
plt.xlabel("$\\sigma_n'$");
plt.ylabel("$\\tau_n'$");
ax = plt.gca();
ax.set_aspect(1);