Statistical programming, matrix languages, and more

matrices

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

matrices

How would I write a subrountine that takes 2 parameters (a constant and a square matrix). Then adds that constant to the every element of the diagonal of the matrix, and passes the results back in a new parameter?

Then out puts the new matrix after the subtracted constant

I have the general idea but getting stuck on the diagonal part.


Accepted Solutions
Solution
‎05-01-2014 03:26 PM
SAS Employee
Posts: 94

Re: matrices

A quick way to add a constant to the diagonal elements of a matrix:

/* add B to diagonal of a square matrix A */

C = A + diag(  j(nrow(A),  1,   B)  );

View solution in original post


All Replies
Solution
‎05-01-2014 03:26 PM
SAS Employee
Posts: 94

Re: matrices

A quick way to add a constant to the diagonal elements of a matrix:

/* add B to diagonal of a square matrix A */

C = A + diag(  j(nrow(A),  1,   B)  );

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 259 views
  • 0 likes
  • 2 in conversation