Skip to content
Back to formatted view

Raw Message

Message-ID: <3EA2BCB3.3040301@pdf.com>
Date: 2003-04-20T15:28:51Z
From: Sundar Dorai-Raj
Subject: loop

Luis Silva wrote:
> Dear helpers
> 
> I have this problem. I want to make a linear combination a*A+(1-
> a)*B where A and B are matrices. I want that a be incremented 
> from 0 to 1 by 0.1 so I made a loop with for. The problem is 
> that I want to keep the result in an object or list or 
> something like that and then apply eigen decomposition to all 
> of the resulting matrices
> 
> sapply(my.list,eigen)
> 
> the problem is that I don't know how to build that list in the 
> loop. I tried several things but it doesn't work (in Matlab i 
> can do it)
> 

a <- seq(0, 1, 0.1)
my.list <- lapply(a, function(a, A, B) a*A + (a-1)*B, A=A, B=B)
names(my.list) <- as.character(a)
sapply(my.list, function(x) eigen(x)$value)

Regards,
Sundar