Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.58 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Plotting the curve of a function with parametric integral using R
  2. n<-3; rho<-0.5;
  3.        
  4. g<-function(r)
  5.    {
  6.      integrate(
  7.        function(beta)
  8.        {
  9.          1/(cosh(beta)-rho*r)^(n-1)
  10.        }
  11.      ,lower=0,upper=Inf)
  12.    }
  13.        
  14. curve(g(x),from=0,to=1)
  15.        
  16. g<-function(r)
  17.     {
  18.       integrate(
  19.         function(beta)
  20.         {
  21.           1/(cosh(beta)-rho*r)^(n-1)
  22.         }
  23.       ,lower=0,upper=Inf)$value   # integrate would return a list otherwise
  24.     }
  25.  gv <- Vectorize(g)  
  26.  # Since `g` is not naturally going to handle the vector that `curve` will send
  27.  curve(gv(x),from=0,to=1)