Statistical programming, matrix languages, and more

Division of matrices of different sizes

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Division of matrices of different sizes

Hello-

I am attempting to divide the values in rows of matrix A by the values in rows of matrix B. the columns of both are the same variables, the rows are different though and the number of rows are different.

I have create a scaled down version below of what I am trying to do:

A{ 1 3, 4 5}

B{ 5 9, 6 2, 7 1}

C{ .2 .33, .166 1.5, .14 3,

.8 .55, .66 2.5, .57 5}

Simply using C=A/B doesn't work, But I am wondering what does? Or if I need to use something other than IML?


Accepted Solutions
Solution
‎05-06-2013 01:56 PM
SAS Super FREQ
Posts: 3,225

Re: Division of matrices of different sizes

Let B1 = 1/B.  Then what you are describing is a "direct product" that involves A and B1.

SAS/IML has two direct products: the "full" direct product is P=A@B.  Your example is the first and last column of that direct product.

The second direct product is computed by using the HDIR function.  What you want is the transpose of HDIR(A`, B1`).

If this is something you intend to use often, you might want to use the following helper function:

start VDIR(A,B);
   return( T(hdir(A`,1/B`)) );
finish;

C = VDIR(A,B);

View solution in original post


All Replies
Solution
‎05-06-2013 01:56 PM
SAS Super FREQ
Posts: 3,225

Re: Division of matrices of different sizes

Let B1 = 1/B.  Then what you are describing is a "direct product" that involves A and B1.

SAS/IML has two direct products: the "full" direct product is P=A@B.  Your example is the first and last column of that direct product.

The second direct product is computed by using the HDIR function.  What you want is the transpose of HDIR(A`, B1`).

If this is something you intend to use often, you might want to use the following helper function:

start VDIR(A,B);
   return( T(hdir(A`,1/B`)) );
finish;

C = VDIR(A,B);

Post a Question
Discussion Stats
  • 1 reply
  • 215 views
  • 0 likes
  • 2 in conversation