Trying to form a large matrix from 1 small matrix
1 view (last 30 days)
Show older comments
Here is the code:
clear all
clc
syms s x
he = 1/22
k_e = [12/(he^3) 12/(he^3) 6/(he^2) 6/(he^2);
12/(he^3) 12/(he^3) -6/(he^2) -6/(he^2);
6/(he^2) -6/(he^2) 4/(he^2) 2/(he^2);
6/(he^2) -6/(he^2) 2/(he^2) 4/(he^2)];
k_g = zeros(46)
for r = 1:23
for c = 1:23
if c = 21
continue
end
if r = 21
continue
end
k_g(r+2,c+2) = k_e;
end
end
k_g
The aim is to insert k_e in k_g after 2 rows and 2 columns and sum the merging values
By "sum mergin vaues", I mean that first time k_e is in k_g, it takes 1,1 to 4,4.
The next time, k_e is inserted starting from 3,3 position and the values at 3,3 3,4 4,3 4,4 are summed with the previous k_e in k_g.
Just as an example, a 2x2 (k_e) which looks like this:
a = [A B C;
D E F;
G H I];
Which added again and again in to b should look like this:
b = [A B C 0 0 0 0;
D E F 0 0 0 0;
G H I+A B C 0 0;
0 0 D E F 0 0;
0 0 G H I+A B C;
0 0 0 0 D E F;
0 0 0 0 G H I];
I hope it clarifies the problem.
Only this time, the a is a 4x4 and b is 46x46 and a is inserted at every (n+2)th row and (n+2)th column
Thanks
0 Comments
Accepted Answer
Alex Hanes
on 24 Oct 2022
Edited: Alex Hanes
on 25 Oct 2022
If I’m following correctly, the following code should get you in the right direction:
k_e = 2*ones(4,4); % place-holder for your symbolic ke
dimB = 46; % set dimension of B-array
B0 = zeros(dimB); % pre-allocate
B = zeros(dimB); % pre-allocate
[m,n] = size(k_e);
B0(1:m,1:n) = k_e; % store k_e in first position
for k = 0:2:dimB-m
B = B + circshift(circshift(B0,k,1),k,2);
end
0 Comments
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!