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

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 Comments

I am getting the following output, not close to the output which you provided (neglecting the index of elements). If you can provide the desired matrix, someone might help you.
A =
164.5920 54.8640 54.8640
0 54.8640 0
0 0 22.8600
Thanks for your reply.
I just neglected the full number but anyway, the desired matrix output should be the following:
[164.5920 54.8640 0;
54.8640 164.5920 0;
0 0 109.72 ]
at least the places of the zeros should be same as the above matrix::
Hope you could help...
Are delAJ and delta always going to be the same thing they are in what you included? If so, what is the purpose of making them have three elements?
If delAJ and delta are constant then the first value of j is the only one that matters, so why bother adding the other two? I would recommend removing the loop for j and saving yourself the time to run it. Just index the second dimension to 1.
I could be wrong, because I don't entirely understand why anything is happening in this code, but I think the indexing issue is in your assigment of C_n into C. As best I can trace out, The placement of zeroes in the array of C(:,1,:,:) is what's causing the assignments to appear messed up. So maybe adjust the IND matrix to reorder them?
Thanks for your reply.
I am not sure, I understand your feedback about delAJ, and delta and I tried to adjust the C, but still can not adjust the IND matrix,
any hints, Would you please modify the lines, so I could see what do you mean exactly ?
Thanks,
Why can't you adjust IND? It is a hard coded matrix, so changing it should be as simple as changing the numbers that make it.
Where does IND come from? Where does C_n come from? How do you know that both are correct, and that your desired output is correct?
Thanks Bob, I tried but I can not, and if I could, I would not write the question here, or seek help here..
C_n is a matrix that I am sure, and compared to other matrix based on example from book...
All the thing is tranferring a 9*9 matrix to a tensor form... at that moment, not sure if the definition is correct or not...
but I am kinda sure, the problem here... the problem in the indexing of the C_n or IND ...
your feedback also mentioned that the problem in IND, or C_n is very possible...
so if you have any hints regarding the code, please do...
Thanks again...
Unfortunately, I personally don't really know how to help much more. It sounds like the math you're doing is not something I really understand, so I don't know how to better direct you. The best I can offer is just to reiterate what I already mentioned, that I believe the issue is coming from your assignment into C (therefore looking at IND and C_n), or the generated values of C_n.
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.
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

Sign in to comment.

Answers (0)

Asked:

on 1 Mar 2021

Edited:

on 3 Mar 2021

Community Treasure Hunt

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

Start Hunting!