Index of matrices in a for loop
1 view (last 30 days)
Show older comments
daniel fonseca
on 16 Feb 2015
Commented: daniel fonseca
on 16 Feb 2015
I want to calculate the matrix Qb but then I want to call any Qb (i) to work only with this array selected for further calculations. For example, I want to calculate Qb (1) to Qb (N) and then make the sum of the matrix Qb or make such Qb (2)xQb (4). I thought of index matrix, but I do not know how. The only way I thought it was like the example for i = 1 and i = 2, but not helpfull for large numbers of i.
if true
% % Variables
N = 6;
Q11 = 2.7770e+10;
Q12 = 1.2517e+09;
Q22 = 5.3037e+09;
Q66 = 2.1011e+09;
Q = [Q11 Q12 0; Q12 Q22 0; 0 0 Q66]
theta = [5*pi*(1/3) (1/4)*pi -(1/4)*pi -(1/4)*pi (1/4)*pi 5*pi*(1/3)]
for i=1:N % Calculation of matrices
teta = theta(i);
Q11b = Q11*cos(teta)^4+(2*(Q12+2*Q66))*sin(teta)^2*cos(teta)^2+Q22*sin(teta)^4
Q12b = (Q11+Q22-4*Q66)*sin(teta)^2*cos(teta)^2+Q12*(sin(teta)^4+cos(teta)^4)
Q22b = Q11*sin(teta)^4+(2*(Q12+2*Q66))*sin(teta)^2*cos(teta)^2+Q22*cos(teta)^4
Q16b = (Q11-Q12-2*Q66)*sin(teta)*cos(teta)^3+(Q12-Q22+2*Q66)*sin(teta)^3*cos(teta)
Q26b = (Q11-Q12-2*Q66)*sin(teta)^3*cos(teta)+(Q12-Q22+2*Q66)*sin(teta)*cos(teta)^3
Q66b = (Q11+Q22-2*Q12-2*Q66)*sin(teta)^2*cos(teta)^2+Q66*(sin(teta)^4+cos(teta)^4)
Qb = [Q11b Q12b Q16b; Q12b Q22b Q26b; Q16b Q26b Q66b]
end
for i=1 % The only way I think of indexing the matrice Qb, but not very helpful for large numbers of i
teta = theta(i);
Q11b = Q11*cos(teta)^4+(2*(Q12+2*Q66))*sin(teta)^2*cos(teta)^2+Q22*sin(teta)^4
Q12b = (Q11+Q22-4*Q66)*sin(teta)^2*cos(teta)^2+Q12*(sin(teta)^4+cos(teta)^4)
Q22b = Q11*sin(teta)^4+(2*(Q12+2*Q66))*sin(teta)^2*cos(teta)^2+Q22*cos(teta)^4
Q16b = (Q11-Q12-2*Q66)*sin(teta)*cos(teta)^3+(Q12-Q22+2*Q66)*sin(teta)^3*cos(teta)
Q26b = (Q11-Q12-2*Q66)*sin(teta)^3*cos(teta)+(Q12-Q22+2*Q66)*sin(teta)*cos(teta)^3
Q66b = (Q11+Q22-2*Q12-2*Q66)*sin(teta)^2*cos(teta)^2+Q66*(sin(teta)^4+cos(teta)^4)
Qb = [Q11b Q12b Q16b; Q12b Q22b Q26b; Q16b Q26b Q66b]
Qb1 = Qb
end
for i=2
teta = theta(i);
Q11b = Q11*cos(teta)^4+(2*(Q12+2*Q66))*sin(teta)^2*cos(teta)^2+Q22*sin(teta)^4
Q12b = (Q11+Q22-4*Q66)*sin(teta)^2*cos(teta)^2+Q12*(sin(teta)^4+cos(teta)^4)
Q22b = Q11*sin(teta)^4+(2*(Q12+2*Q66))*sin(teta)^2*cos(teta)^2+Q22*cos(teta)^4
Q16b = (Q11-Q12-2*Q66)*sin(teta)*cos(teta)^3+(Q12-Q22+2*Q66)*sin(teta)^3*cos(teta)
Q26b = (Q11-Q12-2*Q66)*sin(teta)^3*cos(teta)+(Q12-Q22+2*Q66)*sin(teta)*cos(teta)^3
Q66b = (Q11+Q22-2*Q12-2*Q66)*sin(teta)^2*cos(teta)^2+Q66*(sin(teta)^4+cos(teta)^4)
Qb = [Q11b Q12b Q16b; Q12b Q22b Q26b; Q16b Q26b Q66b]
Qb2 = Qb
end
% And so on until i=N
end
0 Comments
Accepted Answer
Thorsten
on 16 Feb 2015
Edited: Thorsten
on 16 Feb 2015
You compute a 3x3xN matrix where N is are the values of theta as follows
QN(1,1,:) = Q11*cos(theta).^4+(2*(Q12+2*Q66))*sin(theta).^2.*cos(theta).^2+Q22*sin(theta).^4;
QN(1,2,:) = (Q11+Q22-4*Q66)*sin(theta).^2.*cos(theta).^2+Q12*(sin(theta).^4+cos(theta).^4);
QN(1,3,:) = (Q11-Q12-2*Q66)*sin(theta).*cos(theta).^3+(Q12-Q22+2*Q66)*sin(theta).^3.*cos(theta);
QN(2,1,:) = QN(1,2,:);
and so on; note that you have to use .* to multiply matrices point-wise and .^ to raise each element of a matrix.
Then you can select the matrix for the i'th value of theta simply by
QN(:,:,i)
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!