Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 06-27-2018 10:24 AM
(1095 views)

Hello,

I have a block matrix of the form A = {A1, A2, ..., AN} with symmetric matrices A1, .., AN each of the same order 9*9 (N could be as large as 400). I want to shape the matrix in the block-diagonal form B = {C 0 0, 0 D 0, ..., 0 0 E} with matrices of the form C = {2A1 A1 A1, A1 2A1 A1, A1 A1 2A1} and D and E of the same form with A2 vs. AN instead of A1. If I allow loops, I can figure out a solution, but I try to avoid loops. Any suggestions?

Bye, Daniel

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Use Kronecker products to construct the C, D, and E matrices from A1, A2, and A3.

Use the BLOCK function to get the block diagonal matrix of C, D, and E.

```
proc iml;
N = 3;
N2 = N*(N+1)/2;
A1 = sqrsym(1:N2);
A2 = sqrsym(N2:1);
M = j(N, N, 1) + I(N);
C = M @ A1;
D = M @ A2;
print C, D;
B = block(C, D);
print B;
```

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Use Kronecker products to construct the C, D, and E matrices from A1, A2, and A3.

Use the BLOCK function to get the block diagonal matrix of C, D, and E.

```
proc iml;
N = 3;
N2 = N*(N+1)/2;
A1 = sqrsym(1:N2);
A2 = sqrsym(N2:1);
M = j(N, N, 1) + I(N);
C = M @ A1;
D = M @ A2;
print C, D;
B = block(C, D);
print B;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I see the principal idee, but N can be large, so I have to loop in the block part. I try to avoid that loop.

```
proc iml;
p = 3;
N = 2;
start TBlock(AN, p);
M = j(p,p,1) + I(p);
C = M @ AN;
return (C);
finish TBlock;
start AD(N, A, p);
t = 1;
do rs=1 to N;
B = A[t:(t+2),];
BB = TBlock(B, p);
AF = block(AF, BB);
t = t + p;
end;
return (AF);
finish AD;
A1 = {1 2 3,
2 4 5,
3 5 7};
A2 = {1 7 9,
7 8 1,
9 1 1};
AC = A1//A2;
AF = AD(N, AC, p);
print AF;
quit;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.