There are at least two communities of J users.  For the mathematicians, I
would begin with: 

   diag5=: 13 :'y*=\:y'
  
   A=:10 20 30 40
  
  diag5 A
10  0  0  0
 0 20  0  0
 0  0 30  0
 0  0  0 40
  
   diag5
] * [: = \:
   
And end by showing them how J is thinking about the problem.

Linda


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of David Lambert
Sent: Thursday, February 27, 2014 7:09 AM
To: programming
Subject: Re: [Jprogramming] create matrix from diagonal

You've already gotten several solutions.  This is a good time to learn 
of the j essays.

http://www.jsoftware.com/jwiki/Essays/Identity%20Matrix


 >Date: Wed, 26 Feb 2014 22:02:00 -0500
 >From: Joe Bogner <[email protected]>
 >To: [email protected]
 >Subject: [Jprogramming] create matrix from diagonal
 >Message-ID:
 > <caetzv1z8cc0sk52_r-bg9nuqch4vo8suuzzpjsg0m1s5nuh...@mail.gmail.com>
 >Content-Type: text/plain; charset=ISO-8859-1
 >
 >I'm experimenting with svd and am looking for a nicer way of creating
 >a matrix from the S diagonal
 >
 >4 3 2.23607 0
 >
 >needs to be
 >
 >]   (4 4 $ 4 0 0 0 0 3 0 0 0 0 2.23607  0 0 0 0 0 )
 >4 0       0 0
 >0 3       0 0
 >0 0 2.23607 0
 >0 0       0 0
 >
 >What would be the idiomatic way to make that conversion? I tried
 >various versions of reshape and insert.
 >
 >Not quite...
 >
 >],\ S
 >4 0       0 0
 >4 3       0 0
 >4 3 2.23607 0
 >4 3 2.23607 0
 >
 >I also thought about multiplying it by a diagonal matrix of 0s and 1s
 >but couldn't get that figured out either
 >
 >Thanks
 >Joe

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to