[R] Basic Linear Algebra

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Jan 7 09:46:07 CET 2005


"Mulholland, Tom" <Tom.Mulholland at dpi.wa.gov.au> writes:

> > tdata
>      [,1] [,2] [,3] [,4] [,5]
> [1,]    0    1    0   -1   -1
> [2,]    2    0    0   -5   -6
> [3,]    0    0    3   -5   -6
> [4,]    1   -1   -1    0    0
> > sumtd
> [1]  0  0  0 -2
> > 
> 
> which I can calculate to give me 3x+30, x+12, 2x+20,  12x, x

[So presumably you want the complete solution of tdata %*% y == sumtd]
I can't. 4th element should be just 12.
 
> Would someone be kind enough to point me in the right direction as
> to which tools I should be using and any sage words of advice for
> the barely informed.

Just move x*tdata[,5] (where x is y[5]) to the other side of the
equation and solve for each column:

> solve(tdata[,-5],sumtd)
[1] 30 12 20 12
> zapsmall(solve(tdata[,-5],-tdata[,5]))
[1] 3 1 2 0

(A general solution requires a bit more thought. E.g. you run into a
singularity if you try the same idea with the 4th column instead of
the 5th.)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list