Filter löschen
Filter löschen

Code is working:: However, Matrix obtained not correct (Code is working but the zeros elements place are not correct

1 Ansicht (letzte 30 Tage)
Hi all,
I need help in this code,
The Matrix obtained is correct however, the zeros elements are not in the correct place
Should be the following:
[164 54 0;
54 109 0;
0 0 109] ;
I think something is wrong in the indexing, but can not find ??
Below are the code:
clearvars;
clc;
close all;
E11 = 54;
E22 = 54;
v12 = .25;
v23 = .25;
S = zeros(9,9);
S(1,1) = 1/E11;
S(1,2) = -v12/E11;
S(1,3) = S(1,2);
S(2,1) = S(1,2);
S(2,2) = 1/E22;
S(2,3) = -v23/E22;
S(3,1) = S(1,2);
S(3,2) = S(2,3);
S(3,3) = 1/E22;
S(4,4) = (1+v12)/(E11);
S(5,5) = S(4,4);
S(6,6) = S(5,5);
S(7,7) = S(4,4);
S(8,8) = S(5,5);
S(9,9) = S(6,6);
C_n = inv(S);
C(1:3,1:3,1:3,1:3) = zeros(3,3,3,3);
IND =[1 1; 2 2; 3 3; 1 2; 2 3; 3 1; 2 1; 3 2; 1 3]
for m=1:9
for n=1:9
C(IND(m,1),IND(m,2),IND(n,1),IND(n,2)) = C_n(m,n);
end
end
t = 2.54;
delta = [1 1 1]*t;
A = zeros(3,3); % INITALIZATION OF A MATRIX
delAJ = [1 0 0]*(t*t);%permut(j,m,n)*delta(m)*delta(n);
for i = 1:3
for k = 1:3
for j = 1:3
for l = 1:3
A(i,k) = A(i,k) + delAJ(j)/delta(l)*C(i,j,k,l);
end
end
end
end
A
  10 Kommentare
Cris LaPierre
Cris LaPierre am 3 Mär. 2021
Bearbeitet: Cris LaPierre am 3 Mär. 2021
I also played around with changing IND, as well as how you index C in your 4 nested for loops. The issue appears to be more than just a simple indexing issue, as a single change affects the entire output, not just a single value.
Without knowing what it is you are trying to implement, it's hard to determine where your code may be incorrect, especially as you noted, it's working. Could you share details on how S should be created, and what algorithm you are following to create C and to compute A?
Please assume that we are unfamiliar with the actual system you are solving. If you make it easy for us to understand what your code is supposed to be doing, we can probably be of more help.
Mark Sc
Mark Sc am 3 Mär. 2021
Thanks for your reply..
I totally understand what point of view,
Next time, I will try to explain or comment what am I doing
Thanks again

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by