On Aug 28, 2010, at 10:12 AM, (Ted Harding) wrote:

On 28-Aug-10 13:15:47, Cuckovic Paik wrote:
Thank all help help. Ted's intuitive single step definition
is what I want.
I try to teach elementary Linear Algebra using R to manupilate
matrices.
Since my students have no programming experience at all, any fancy and
muliple step definition in matrix row operation will confuse them.
Again, I appreciate the suggestions from all of you!
--

Just to avoid any misunderstanding: My contribution was an explanatory
comment to Gabor's solution. It was Gabor who gave the solution!

But, while I am at it, if you are teaching elementary Linear Algebra
and matrix manipulation, note that the desired result (rows 1, 2 & 4
of A, with row 3 = 2*(row 1 of A) + (row 3 of A)) can be obtained
using a matrix product:

1  0  0  0  %*%   1  5  9 13
0  1  0  0        2  6 10 14
2  0  1  0        3  7 11 15
0  0  0  1        4  8 12 16

Which was exactly what my solution was doing, since it becomes in expanded form :

D2 <-  I %*% A2 + matrix (c(0,0,2,rep(0,13)), 4) %*% A2 =

1  0  0  0  %*%   1  5  9 13  +  0  0  0  0  %*%   1  5  9 13
0  1  0  0        2  6 10 14     0  0  0  0        2  6 10 14
0  0  1  0        3  7 11 15     2  0  0  0        3  7 11 15
0  0  0  1        4  8 12 16     0  0  0  0        4  8 12 16

And A %*% C + B %*% C = (A+B) %*% C and

1  0  0  0   +  0  0  0  0  =  1  0  0  0
0  1  0  0      0  0  0  0     0  1  0  0
0  0  1  0      2  0  0  0     2  0  1  0
0  0  0  1      0  0  0  0     0  0  0  1

There are other elementary operations that can be expressed as matrix operations:
Swapping rows 2 and 3 for instance by pre-multiplication by:

1  0  0  0
0  0  1  0
0  1  0  0
0  0  0  1

== matrix (c(1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1), 4)

Or swapping cols 2 and 3 by post multiplication with the same matrix.

--
David.





i.e. (in R):

 (diag(nrow(A)) + c(0,0,2,0, 0,0,0,0, 0,0,0,0, 0,0,0,0))%*%A
 #      [,1] [,2] [,3] [,4]
 # [1,]    1    5    9   13
 # [2,]    2    6   10   14
 # [3,]    5   17   29   41
 # [4,]    4    8   12   16

(as before).
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.hard...@manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 28-Aug-10                                       Time: 15:12:03
------------------------------ XFMail ------------------------------

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to