how do you substitute all iterations of symbolic sin^2theta cos^2theta with 1 in this symbolic MATLAB matrix to have a more simplified output?

3 views (last 30 days)
clear
clc
% declaration of given variable
syms A;
syms E;
syms I;
syms L;
% c = cos(theta) and s = sin(theta)
% syms c;
% syms s;
syms theta;
c = cos(theta);
s = sin(theta);
% creation of global stiffness matrix
k = sym(zeros(6,6));
k(1,1) = (A*E)/L;
k(1,4) = -(A*E)/L;
k(2,2) = (12*E*I)/(L^3);
k(2,3) = (6*E*I)/(L^2);
k(2,5) = -(12*E*I)/(L^3);
k(2,6) = (6*E*I)/(L^2);
k(3,2) = (6*E*I)/(L^2);
k(3,3) = (4*E*I)/(L);
k(3,5) = -(6*E*I)/(L^2);
k(3,6) = (2*E*I)/(L);
k(4,1) = -(A*E)/L;
k(4,4) = (A*E)/L;
k(5,2) = -(12*E*I)/(L^3);
k(5,3) = -(6*E*I)/(L^2);
k(5,5) = (12*E*I)/(L^3);
k(5,6) = -(6*E*I)/(L^2);
k(6,2) = (6*E*I)/(L^2);
k(6,3) = (2*E*I)/(L);
k(6,5) = -(6*E*I)/(L^2);
k(6,6) = (4*E*I)/(L);
% Creation of the transformation matrix
T = sym(zeros(6,6));
T(1,1) = c;
T(1,2) = s;
T(2,1) = -s;
T(2,2) = c;
T(3,3) = 1;
T(4,4) = c;
T(4,5) = s;
T(5,4) = -s;
T(5,5) = c;
T(6,6) = 1;
% generating the global stiffness matrix
t = inv(T);
K = mtimes(t,k);
K = mtimes(K,T);
fprintf('The Stiffness matrix is:\n%s\n\n', char(K));
fprintf('Note that c^2 + s^2 = 1');
Output
The Stiffness matrix is:
matrix([[(A*E*cos(theta)^2)/(L*(cos(theta)^2 + sin(theta)^2)) + (12*E*I*sin(theta)^2)/(L^3*(cos(theta)^2 + sin(theta)^2)), (A*E*cos(theta)*sin(theta))/(L*(cos(theta)^2 + sin(theta)^2)) - (12*E*I*cos(theta)*sin(theta))/(L^3*(cos(theta)^2 + sin(theta)^2)), -(6*E*I*sin(theta))/(L^2*(cos(theta)^2 + sin(theta)^2)), - (A*E*cos(theta)^2)/(L*(cos(theta)^2 + sin(theta)^2)) - (12*E*I*sin(theta)^2)/(L^3*(cos(theta)^2 + sin(theta)^2)), (12*E*I*cos(theta)*sin(theta))/(L^3*(cos(theta)^2 + sin(theta)^2)) - (A*E*cos(theta)*sin(theta))/(L*(cos(theta)^2 + sin(theta)^2)), -(6*E*I*sin(theta))/(L^2*(cos(theta)^2 + sin(theta)^2))], [(A*E*cos(theta)*sin(theta))/(L*(cos(theta)^2 + sin(theta)^2)) - (12*E*I*cos(theta)*sin(theta))/(L^3*(cos(theta)^2 + sin(theta)^2)), (12*E*I*cos(theta)^2)/(L^3*(cos(theta)^2 + sin(theta)^2)) + (A*E*sin(theta)^2)/(L*(cos(theta)^2 + sin(theta)^2)), (6*E*I*cos(theta))/(L^2*(cos(theta)^2 + sin(theta)^2)), (12*E*I*cos(theta)*sin(theta))/(L^3*(cos(theta)^2 + sin(theta)^2)) - (A*E*cos(theta)*sin(theta))/(L*(cos(theta)^2 + sin(theta)^2)), - (12*E*I*cos(theta)^2)/(L^3*(cos(theta)^2 + sin(theta)^2)) - (A*E*sin(theta)^2)/(L*(cos(theta)^2 + sin(theta)^2)), (6*E*I*cos(theta))/(L^2*(cos(theta)^2 + sin(theta)^2))], [-(6*E*I*sin(theta))/L^2, (6*E*I*cos(theta))/L^2, (4*E*I)/L, (6*E*I*sin(theta))/L^2, -(6*E*I*cos(theta))/L^2, (2*E*I)/L], [- (A*E*cos(theta)^2)/(L*(cos(theta)^2 + sin(theta)^2)) - (12*E*I*sin(theta)^2)/(L^3*(cos(theta)^2 + sin(theta)^2)), (12*E*I*cos(theta)*sin(theta))/(L^3*(cos(theta)^2 + sin(theta)^2)) - (A*E*cos(theta)*sin(theta))/(L*(cos(theta)^2 + sin(theta)^2)), (6*E*I*sin(theta))/(L^2*(cos(theta)^2 + sin(theta)^2)), (A*E*cos(theta)^2)/(L*(cos(theta)^2 + sin(theta)^2)) + (12*E*I*sin(theta)^2)/(L^3*(cos(theta)^2 + sin(theta)^2)), (A*E*cos(theta)*sin(theta))/(L*(cos(theta)^2 + sin(theta)^2)) - (12*E*I*cos(theta)*sin(theta))/(L^3*(cos(theta)^2 + sin(theta)^2)), (6*E*I*sin(theta))/(L^2*(cos(theta)^2 + sin(theta)^2))], [(12*E*I*cos(theta)*sin(theta))/(L^3*(cos(theta)^2 + sin(theta)^2)) - (A*E*cos(theta)*sin(theta))/(L*(cos(theta)^2 + sin(theta)^2)), - (12*E*I*cos(theta)^2)/(L^3*(cos(theta)^2 + sin(theta)^2)) - (A*E*sin(theta)^2)/(L*(cos(theta)^2 + sin(theta)^2)), -(6*E*I*cos(theta))/(L^2*(cos(theta)^2 + sin(theta)^2)), (A*E*cos(theta)*sin(theta))/(L*(cos(theta)^2 + sin(theta)^2)) - (12*E*I*cos(theta)*sin(theta))/(L^3*(cos(theta)^2 + sin(theta)^2)), (12*E*I*cos(theta)^2)/(L^3*(cos(theta)^2 + sin(theta)^2)) + (A*E*sin(theta)^2)/(L*(cos(theta)^2 + sin(theta)^2)), -(6*E*I*cos(theta))/(L^2*(cos(theta)^2 + sin(theta)^2))], [-(6*E*I*sin(theta))/L^2, (6*E*I*cos(theta))/L^2, (2*E*I)/L, (6*E*I*sin(theta))/L^2, -(6*E*I*cos(theta))/L^2, (4*E*I)/L]])
Note that c^2 + s^2 = 1>>

Answers (1)

James Tursa
James Tursa on 11 Feb 2020
simplify(K)

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!