How allocate a matrix to grids?

9 views (last 30 days)
Hamideh Rouhani
Hamideh Rouhani on 19 Nov 2023
Commented: Matt J on 21 Nov 2023
I want to use staggered grid to write MATLAB code about viscoelastic fluid. You suppose I have a 10×14 node at x and y direction. I have initial value for conformation tensor as A=[1 , 0 ;0  1] I should allocate this value for all grids as matrix.  Then It should calculate eigen values of A matrix and also its normalized vectors. Then put eigen values in matrix as diagonal matrix as "Lamda". Then Z= Rt *Lambda*R Which RT is transpose of normalazed matrix of A. Now I do not know how should I define matrix (A) as the input , that the new one will replace with the previous in the loop. I defined as this: A (i,j)=eye(2) Or A11(i,j)=1, A12(i,j)0 , A21(i,j)=0 , A22(i,j)=1
But it gives error about dimension.
If I define A=eye(2), how MATLAB understand put this value in each node and in the next step replace it with new one which the value can be different from each grid to other one.

Answers (1)

Matt J
Matt J on 19 Nov 2023
Edited: Matt J on 19 Nov 2023
You could have a 4 dimensional array
A=repmat(eye(2) ,1,1,10,14)
A =
A(:,:,1,1) = 1 0 0 1 A(:,:,2,1) = 1 0 0 1 A(:,:,3,1) = 1 0 0 1 A(:,:,4,1) = 1 0 0 1 A(:,:,5,1) = 1 0 0 1 A(:,:,6,1) = 1 0 0 1 A(:,:,7,1) = 1 0 0 1 A(:,:,8,1) = 1 0 0 1 A(:,:,9,1) = 1 0 0 1 A(:,:,10,1) = 1 0 0 1 A(:,:,1,2) = 1 0 0 1 A(:,:,2,2) = 1 0 0 1 A(:,:,3,2) = 1 0 0 1 A(:,:,4,2) = 1 0 0 1 A(:,:,5,2) = 1 0 0 1 A(:,:,6,2) = 1 0 0 1 A(:,:,7,2) = 1 0 0 1 A(:,:,8,2) = 1 0 0 1 A(:,:,9,2) = 1 0 0 1 A(:,:,10,2) = 1 0 0 1 A(:,:,1,3) = 1 0 0 1 A(:,:,2,3) = 1 0 0 1 A(:,:,3,3) = 1 0 0 1 A(:,:,4,3) = 1 0 0 1 A(:,:,5,3) = 1 0 0 1 A(:,:,6,3) = 1 0 0 1 A(:,:,7,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0 1 A(:,:,10,13) = 1 0 0 1 A(:,:,1,14) = 1 0 0 1 A(:,:,2,14) = 1 0 0 1 A(:,:,3,14) = 1 0 0 1 A(:,:,4,14) = 1 0 0 1 A(:,:,5,14) = 1 0 0 1 A(:,:,6,14) = 1 0 0 1 A(:,:,7,14) = 1 0 0 1 A(:,:,8,14) = 1 0 0 1 A(:,:,9,14) = 1 0 0 1 A(:,:,10,14) = 1 0 0 1
  4 Comments
Matt J
Matt J on 21 Nov 2023
You are quite welcome, but please Accept-click the answer if it resolved your question.

Sign in to comment.

Categories

Find more on Programming 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!