90 likes | 198 Views
SAS Interactive Matrix Language Computing for Research I Spring 2012 Ramesh. Solve this system of linear equations: 3 x + 2 y − 4z = 11 5 x − 4 y = 9 3 y + 10 z = 42 In matrix form. =. =. Reading in Data. proc iml ; n = 3 ; *scalar; b = { 11 9 42 }; *1 x 3 row vector;
E N D
SAS Interactive Matrix Language Computing for Research I Spring 2012 Ramesh
Solve this system of linear equations: • 3x + 2y − 4z = 11 • 5x − 4y = 9 • 3y + 10z = 42 • In matrix form = =
Reading in Data prociml; n = 3; *scalar; b = {11942}; *1 x 3 row vector; A = {32 -4, 5 -40, 0310}; *3 x 3 matrix; print n b a; quit;
Matrix Operators: Arithmetic Addition: + Subtraction: - Division, Elementwise: / Multiplication, Elementwise: # Multiplication, Matrix: * Power, Elementwise: ## Power, Matrix: ** Concatenation, Horizontal: || Concatenation, Vertical: // Number of rows: nrow() Number of columns: ncol()
Subscript Operations [ ] • Addition + • Multiplication # • Mean : • Sum of squares ## • Maximum <> • Minimum >< • Index of maximum <:> • Index of minimum >:< • Transpose: ` (Near number 1 on keyboard) • Determinant: det(matrix) • Inverse: inv(matrix) • Trace: tr(matrix) • Select a single element: i,j • Select a row: i, • Select a column: ,j
Creating special Matrices: • Identity matrix with dimension = size:I(size) • Matrix having # rows = nrow # cols = ncol with all elements = x :j(nrow,ncol,x) • Diagonal matrix: diag(vector) (diag(matrix)) • Block diagonal matrix: block (M1, M2, ...)
Calling SAS PROC’s into IML prociml; callrandseed(9087235); y = j(400,1); callrandgen(y,normal'); z = j(100,1); callrandgen(z,'normal', 2, 2.5); x = y // z; create a var{"x"}; append; close a; submit; procunivariatedata=a; var x; histogram /kernel; run; endsubmit;
Using DO loops prociml; doi=1to3; callrandseed(9087235); mean=i*2; var=0.5*i; y = j(400,1); callrandgen(y, 'normal'); z = j(100,1); callrandgen(z, 'normal',mean, var); x = y // z; createa var {"x"}; append; close a; submit; procunivariatedata=a noprint; varx; histogram/ kernel; run; endsubmit; end;
datamult; • input v1 v2 v3; • datalines; • 0.801 121.41 70.42 • 0.824 127.70 72.47 • 0.841 129.20 78.20 • 0.816 131.80 74.89 • 0.840 135.10 71.21 • 0.842 131.50 78.39 • 0.820 126.70 69.02 • 0.802 115.10 73.10 • 0.828 130.80 79.28 • 0.819 124.60 76.48 • 0.826 118.31 70.25 • 0.802 114.20 72.88 • 0.810 120.30 68.23 • 0.802 115.70 68.12 • ; • prociml; • usemult; • read all into v; • X=v`*v; • print v; • run;