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

I did try OPT2=INV(A)*b; right after the matrices.

 

I get the error "ERROR: Argument 'matrix' (#1) must be a square matrix"

 

So, there is my answer.

 

But previously, I was trying to run your full code and got a different error. I wasn't sure how to select column 1 and column 3.

Rick_SAS
SAS Super FREQ

I encourage you to discuss these questions with your classmates or professor. Lots of good opportunities to learn!

 

I think you will discover that the length of b must be the same as the number of rows as A. (Why?) However, the length of the solution vector, x, will change (Why?) 

 

If you look back at my program, you will find that I do not use the INV function. (Why?)

 

To answer your question, you can extract columns 1 and 3 of a matrix by listing those indices as the subscripts for the columns:

C = A[ , {1 3}];

edasdfasdfasdfa
Quartz | Level 8

 

a. b has to be the same length as the rows of A because the resulting b vector of Ax should be a 2*1 vector (2 rows, 1 column). For some reason even though I was changing b mistakenly, I was thinking of x in my head (that I was changing x). So easy to get confused if you don't write stuff down.

 

b. x has to be a 3*1 for the matrix operations to work (element-wise multiplication). The columns of A have to be equal to the rows of x.

 

c. You used ginv instead of inv because the generalized inverse can be used for non-square matrices with rank deficient A's and inv can't be?

 

 

edasdfasdfasdfa
Quartz | Level 8

@Rick_SAS 

Hey Rick,

Could you breakdown this projection formula?

One thing I'm not understanding is how this formula changes when the Matrix is bigger.

 

A1 = A[,1];
p = (A1`*b)/norm(A1)**2 * A1;
print p;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 20 replies
  • 1658 views
  • 7 likes
  • 3 in conversation