BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasone
Quartz | Level 8

いつも大変お世話になっております。
proc IMLでベクトルの内積および外積の計算はできますでしょうか?
他のプロシジャやデータステップを用いて上記計算は出来なくはないのですが、
IMLで直接算出できればそれに越したことはないかと思いまして。
しかしIMLのinner or outer productに関する参考文献が見当たりません。

以上ご教示のほど、何卒よろしくお願いいたします。

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

See "Ways to multiply in the SAS/IML language."

The vector product you want is at the end of the article. The name I learned is "vector cross product."

Here is a SAS/IML module that computes it:

 

proc iml;
/* vector cross product (3D vectors only) */
start CrossProd(u, v);
   i231 = {2 3 1};
   i312 = {3 1 2};
   return( u[i231]#v[i312] - v[i231]#u[i312] );
finish;
 
x = { 1, 2, 3};/* 3x1 column vector */
y = { 3, 2, 1};/* 3x1 column vector */
outer = CrossProd(x, y);
print outer;


View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

それらは行列乗算を使用して計算されます

 

proc iml;
x = { 1, 2, 3, 4,  5};
y = {-2, 0, 1, 2, -3};

inner = x` * y;  /* ベクトルの内積 */
outer = x  * y`; /* ベクトルの外積 */

print inner, outer;
sasone
Quartz | Level 8

Hi, Mr. Rick.
Thank you very much for an immediate answer.

proc iml;
x = { 1, 0};/* 2x1 column vector */
y = { 0.5, 0.866};/* 2x1 column vector */
inner = x` * y;  /* ベクトルの内積 */
print inner;

The returned scalar value 0.5 is corresponding to cosine 60 degree !
(x・y=|x||y|cosθ:θ=60)

 

However, I'm sorry, the outer product(vector product) is different that I demand.

proc iml;
x = { 1, 2, 3};/* 3x1 column vector */
y = { 3, 2, 1};/* 3x1 column vector */
outer = x  * y`; /* ベクトルの外積 */
print outer;

But, the answer that I demand, outer={2*1 - 2*3 , 3*3 - 1*1 , 1*2 - 3*2}
={-4,8,-4}. /* 3x1 column vector */


Best regards.

Rick_SAS
SAS Super FREQ

See "Ways to multiply in the SAS/IML language."

The vector product you want is at the end of the article. The name I learned is "vector cross product."

Here is a SAS/IML module that computes it:

 

proc iml;
/* vector cross product (3D vectors only) */
start CrossProd(u, v);
   i231 = {2 3 1};
   i312 = {3 1 2};
   return( u[i231]#v[i312] - v[i231]#u[i312] );
finish;
 
x = { 1, 2, 3};/* 3x1 column vector */
y = { 3, 2, 1};/* 3x1 column vector */
outer = CrossProd(x, y);
print outer;


sasone
Quartz | Level 8

A careful answer, thank you very much.
This is the answer that I want !
I understood "Vector Cross Product".

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Discussion stats
  • 4 replies
  • 1442 views
  • 10 likes
  • 2 in conversation