Java Mailing List Archive

http://www.r-help.com/

Home » Home (12/2007) » R Help for Statistical Computing »

[R] matlab norm(h) command in R: sqrt(sum(h^2)) - use in an
 expression

Christoph Lehmann

2005-02-15

Replies:

Hi

in matlab I defined a function (double gamma, parameters at the end of
this mail) as
 h(i)=((t/d1)^a1)*exp(-(t-d1)/b1)-c*((t/d2)^a2)*exp(-(t-d2)/b2);
 h=h/norm(h);

I do know that norm() in matlab is equal to:

 sqrt(sum(x^2))
in R
so in R I do it like:

#function (double gamama)
h <- expression((t/d1)^a1*exp(-(t-d1)/b1)-c*(t/d2)^a2*exp(-(t-d2)/b2))

# plot it
t <- seq(0, 20000, by = 100)
t <- t/1000
plot(eval(h), type = 'l')

# however this yields an error
h <- h/sqrt(sum(h^2))
Error in h^2 : non-numeric argument to binary operator

what shall I do to get the matlab: h = h/norm(h) implemented in R?

thanks for a hint

christoph


----
# parameters
peak1 <- 5.4
fwhm1 <- 5.2
peak2 <- 10.8
fwhm2 <- 7.35
dip <- 0.35

b1 <- 0.9 # dispersion
b2 <- 0.9 #dispersion
a1 <- peak1/b1
a2 <- peak2/b2
d1 <- a1*b1
d2 <- a2*b2
c <- dip

______________________________________________
R-help@(protected)
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
©2008 r-help.com - Jax Systems, LLC, U.S.A.