A= [3, 2, 1; 5, 7, 4; 9, 6, 8];
disp(A);
B=A';
disp(B)
disp(A);
d = det(A);
disp(d)
A = randi([0, 10], [3,3]);
disp('The matrix A is:')
disp(A)
B = randi([0, 10], [3,3]);
disp('The matrix B is:')
disp(B)
C=A*B;
d=det(C);
e=det(A)*det(B);
fprintf("LHS: %f\n", d);
fprintf("RHS: %f\n", e);
fprintf("Relerr: %f", abs(1-d/e));
disp(A)
a = det(A); disp(a);
B = inv(A); disp(B)
C=A*B; disp(round(C))
format short g
LHS= (inv(A))';
LHS = round(10000 * LHS) / 10000;
RHS= inv(A');
RHS = round(10000 * RHS) / 10000;
disp(LHS)
disp(RHS)
isequal(LHS,RHS)
compare= (LHS==RHS)
A = randi([0, 10], [3,3]);
B = randi([0, 10], [3,3]);
C=A*B;
disp('The matrix C is:')
disp(C)
D=B*A;
disp('The matrix D is:')
disp(D)
compare= (C==D)
function check_symm(Matrix)
if (isequal(Matrix, Matrix')==1);
fprintf("This is a symmetric matrix");
else
fprintf("This is not a symmetric matrix");
end
end
A= [1, 2, 3; 2, 4, 5; 3, 5, 6];
B= [3, 3, 9; 9, 4, 9; 8, 8, 3];
disp("The matrix A is")
disp(A);
disp("The matrix B is")
disp(B);
check_symm(A)
check_symm(B)
disp("The matrix A is")
disp(A);
disp("The matrix B is")
disp(B);
C = sum(dot(A,B))
function double_dot(A,B)
S=0;
for i=1:1:3
for j=1:1:3
S = S + A(i,j)*B(i,j);
end
end
fprintf("The double-dot product is: %d\t", S);
end
double_dot(A,B)
$\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*pi/180;
Q = [cos(theta), sin(theta); -sin(theta), cos(theta)];
disp(Q)
c = det(Q); disp(c);
lhs = Q';
rhs = inv(Q);
if (isequal(LHS,RHS)==1)
fprintf("TRUE \n");
end
compare= (LHS==RHS)
I = eye(2); disp(I);
compare (Q*Q'==I)
a = [1; 3];
ap = Q*a;
disp(ap)
# vary Theta from 0 to 2pi radians
theta_a = linspace(0, 2*pi, 100); # Theta in radians
# Elements of vector in initial frame: theta = 0
a = [1, 3]';
# Generate a matrix to store the transformed elements for correspoding theta
ap1_a = zeros(size(theta_a));
ap2_a = zeros(size(theta_a));
# Iterate over theta values and assign the values to ap1_a and ap2_a
for i=1:length(theta_a)
theta = theta_a(i);
Q = [cos(theta), sin(theta); -sin(theta), cos(theta)];
ap = Q*a;
ap1_a(i) = ap(1); # 1st element, index = 1
ap2_a(i) = ap(2); # 2nd element, index = 2
end
set(0, "defaultlinelinewidth", 5);
set (0, "defaulttextfontname", "TimesNewRoman")
set (0, "defaulttextfontsize", 20)
set (0, "DefaultAxesFontName", "TimesNewRoman")
set(0, 'DefaultAxesFontSize', 20)
plot(theta_a, ap1_a, "-;a'_1;");
hold on;
plot(theta_a, ap2_a, "-;a'_2;");
grid on;
xlabel("\\theta");
ylabel("Components of a'");
h = legend();
legend (h, "location", "southwest");
legend boxoff;
set (h, "fontsize", 16,"fontname", "TimesNewRoman");
hold off;
plot(ap1_a, ap2_a);
hold on;
plot(a(1), a(2), 'ok'); # initial vector
daspect([1 1]);
hold off;
theta = 30*pi/180;
Q =[cos(theta), sin(theta);-sin(theta), cos(theta)];
# Original state of stress
s = [50, 30; 30, -20];
disp(s)
# Transformed matrix
sp =(Q*s)*Q';
disp(sp)
theta_a = linspace(0, pi, 100); # Theta in radians
sigma_n_a = zeros(size(theta_a));
tau_n_a = zeros(size(theta_a));
for i=1:length(theta_a)
theta = theta_a(i);
Q =[cos(theta), sin(theta);-sin(theta), cos(theta)];
s = [50, 30; 30, -20];
sp =(Q*s)*Q';
sigma_n_a(i) = sp(1,1);
tau_n_a(i) = sp(1,2);
end
plot(sigma_n_a, tau_n_a);
hold on;
plot(trace(s)/2, 0, 'ok'); # center of the circle
xlabel("\\sigma_n'");
ylabel("\\tau_n'");
daspect([1 1]);
hold off;