Index of matrices in a for loop
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!