Hi all, I am using the 'gaussHermite' function from the 'pracma' library ############ CODES ########### library(pracma) cc=gaussHermite(10) cc$x^2 cc$x^5 cc$x^4 ############ CODES ########### as far so good. However, it does NOT work for any NON integer values, say ############ CODES ########### cc$x^(2.5) cc$x^(-2.5) ############ CODES ########### But just think about it numberically, it should work..... why this is the case? Is there a reason for getting the "NaN"s? Thanks! ----- ###################### PhD candidate in Statistics Big R Fan Big LEGO Fan Big sTaTs Fan ###################### -- View this message in context: http://r.789695.n4.nabble.com/problem-with-Gauss-Hermite-x-and-w-tp4622115.html Sent from the R help mailing list archive at Nabble.com.
problem with Gauss Hermite ( x and w )
6 messages · casperyc, Rui Barradas, R. Michael Weylandt
Taking negative numbers to fractional powers gives NaNs.... that's just how it works. Unless you want to use complex numbers (which R does not by default): as.complex(cc$x) ^ (2.5) Michael
On Wed, May 9, 2012 at 7:22 PM, casperyc <casperyc at hotmail.co.uk> wrote:
Hi all, I am using the 'gaussHermite' function from the 'pracma' library ############ CODES ########### library(pracma) cc=gaussHermite(10) cc$x^2 cc$x^5 cc$x^4 ############ CODES ########### as far so good. However, it does NOT work for any NON integer values, say ############ CODES ########### cc$x^(2.5) cc$x^(-2.5) ############ CODES ########### But just think about it numberically, it should work..... why this is the case? Is there a reason for getting the "NaN"s? Thanks! ----- ###################### PhD candidate in Statistics Big R Fan Big LEGO Fan Big sTaTs Fan ###################### -- View this message in context: http://r.789695.n4.nabble.com/problem-with-Gauss-Hermite-x-and-w-tp4622115.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
Hi, I know what complex number are, but I am not sure what you meant by that? ##############CODES###########
2.5^(-2.4)
[1] 0.1109032
-2.5^(-2.4)
[1] -0.1109032 ##############CODES########### works fine. Negative powers mean they take the reciprocal and as far as I am concerned, real^real is just a real number. Am I mistaking something basic? Thanks. Casper ----- ###################### PhD candidate in Statistics Big R Fan Big LEGO Fan Big sTaTs Fan ###################### -- View this message in context: http://r.789695.n4.nabble.com/problem-with-Gauss-Hermite-x-and-w-tp4622115p4624395.html Sent from the R help mailing list archive at Nabble.com.
Hello,
Negative powers mean they take the reciprocal and as far as I am concerned, real^real is just a real number. Am I mistaking something basic?
Yes, you are. real^real is not necessarily real. The most well known example is (-1)^0.5 = imaginary unit. When you say that -2.5^(-2.4) is real you're computing the negative power of a POSITIVE real, 2.5 then taking the result's symmetric. (-2.5)^(-2.4) [1] NaN Or (-1)^0.5 [1] NaN -1^0.5 [1] -1 (-1 + 0i)^0.5 # algebraically, equal to (-1)^0.5 above, but not in R notation. [1] 0+1i Hope this helps, Rui Barradas casperyc wrote
Hi, I know what complex number are, but I am not sure what you meant by that? ##############CODES###########
2.5^(-2.4)
[1] 0.1109032
-2.5^(-2.4)
[1] -0.1109032 ##############CODES########### works fine. Negative powers mean they take the reciprocal and as far as I am concerned, real^real is just a real number. Am I mistaking something basic? Thanks. Casper
-- View this message in context: http://r.789695.n4.nabble.com/problem-with-Gauss-Hermite-x-and-w-tp4622115p4624486.html Sent from the R help mailing list archive at Nabble.com.
Rui Barradas wrote
real^real is not necessarily real. The most well known example is (-1)^0.5 = imaginary unit.
Damn, can't believe it! It's a silly mistake! Now that something wonders me is that when applying the Gaussian Hermit, sum w f(x_i) What happens when f(x_i) does not work? This has nothing to do with R, I will try read more on the material myself. Thank you all! Casper ----- ###################### PhD candidate in Statistics Big R Fan Big LEGO Fan Big sTaTs Fan ###################### -- View this message in context: http://r.789695.n4.nabble.com/problem-with-Gauss-Hermite-x-and-w-tp4622115p4624557.html Sent from the R help mailing list archive at Nabble.com.
Are you getting caught on order of operations? Note that unary minus has lower precedence than exponentiation (as it does in math) so -2.5^(-2.4) is x <- 2.5^(-2.4) -x Otherwise, I'm not at all sure what your question is: can you give an example of what you think you should get (and how to get it) and what R is giving you instead? Michael
On Thu, May 10, 2012 at 2:30 PM, casperyc <casperyc at hotmail.co.uk> wrote:
Hi, ?I know what complex number are, but I am not sure what you meant by that? ##############CODES###########
2.5^(-2.4)
[1] 0.1109032
-2.5^(-2.4)
[1] -0.1109032 ##############CODES########### works fine. Negative powers mean they take the reciprocal and as far as I am concerned, real^real is just a real number. Am I mistaking something basic? Thanks. Casper ----- ###################### PhD candidate in Statistics Big R Fan Big LEGO Fan Big sTaTs Fan ###################### -- View this message in context: http://r.789695.n4.nabble.com/problem-with-Gauss-Hermite-x-and-w-tp4622115p4624395.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.