An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090310/5312e08a/attachment-0002.pl>
Matrices in R - Simple question?
2 messages · Lars Bishop, David Winsemius
I suspect you probably need to provide an example that illustrates why this seems difficult: > x <- 1:10 > f1 <- function(x) exp(x) > g1 <- function (x) log(x) > h1 <- function (x) x^(1/2) # any of these functions would return a 10 element vector if given x as an argument > f1(x)*g1(x)*h1(x) [1] 0.000000e+00 7.243182e+00 3.821981e+01 1.513782e+02 5.341111e+02 1.770607e+03 5.645900e+03 1.753265e+04 5.341289e+04 [10] 1.603838e+05 > sum( f1(x)*g1(x)*h1(x) ) [1] 239476.8 Examples might help ....
David Winsemius On Mar 10, 2009, at 7:38 PM, Lars Bishop wrote: > Hi, > > I'm a new R user and would appreciate your help regarding the > following: Can > I create a matrix whose elements are n functions of a vector x? In my > problem I have 3 vectors (a,b,c) with elements a=[f1(x) > f2(x)....fn(x)]; > b=[g1(x) g2(x)....gn(x)]; c=[h1(x) h2(x)....hn(x)]. > I need to create a final > function that looks like: f(x)=f1(x)*g1(x)*h1(x)+..... > +fn(x)*gn(x)*hn(x). > (f(x) is my objective function of an optimization problem).Is this > possible > to create f(x) in the way I described? > > > Many thanks in advance for your help! > > Lars. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. David Winsemius, MD Heritage Laboratories West Hartford, CT