1. Posts in the subject areas are now being moderated. Please do not post any details about your exam for at least 3 working days. You may not see your post appear for a day or two. See the 'Forum help' thread entitled 'Using forums during exam period' for further information. Wishing you the best of luck with your exams.
    Dismiss Notice

Integration in R

Discussion in 'Off-topic' started by r_v.s, May 11, 2014.

  1. r_v.s

    r_v.s Ton up Member

    I really dint know where this question should have been posted!

    Is it possible to evaluate an integral in R when one of the limits is a variable?
    The integration with constant limits works! If R wont do this, would you suggest a software package that would??
     
  2. Oxymoron

    Oxymoron Ton up Member

    Do you mean like below? If so, MATLAB can do it.

    >> syms x y
    >> f = y^3 - y^2 + 1

    f = y^3 - y^2 + 1

    >> int(f,y,1,x)

    ans = x*(x^2*(x/4 - 1/3) + 1) - 11/12
     
  3. r_v.s

    r_v.s Ton up Member

    Yes. infact, the expression is complicated
    It is a joint distribution function so, but the limits are from -infinity to x.
     
  4. Oxymoron

    Oxymoron Ton up Member

    Yup MATLAB can handle all that.
     
  5. Calum

    Calum Member

    The specific code would help. I suspect it will just need a tweak to get the correct behaviour.
     
  6. r_v.s

    r_v.s Ton up Member

    library(cubature)

    k = 0.618079
    rho = 0.402193
    k1 = (1+s^2/4)^2.5
    k2 = 4*(1-rho)^0.5

    f1 = function(r,s)
    {
    (k*k1*(1+(r^2)/4)^2.5*(1+(s^2-2*rho*s*r+r^2)/k2)^-2.5
    }
    ##I need to integrate the above twice from (-inf , qt(0.75,4)) wrt s and (-inf , qt(v,4)) wrt r.
    Finally i require an expression in v, which i then need to integrate from (0,1).

    I'd be glad of any help!
     
  7. Oxymoron

    Oxymoron Ton up Member

    What's qt(0.75,4)?
     
  8. Oxymoron

    Oxymoron Ton up Member

    If I do it from -inf to inf, MATLAB says explicit integral can't be found. Is the density correct?
     
  9. Calum

    Calum Member

    These, I think, are your problem. I think you want to define k1, k2 as functions of s, as at the moment k1, k2 will just become vectors containing whatever values of s are currently in memory.
     
  10. r_v.s

    r_v.s Ton up Member

    qt is the quantile function in r.
    i just used k1 and k2 for convenience,
    i've tried it with the constants plugged in, in the
    equation, and was still unable to do it.
     
  11. r_v.s

    r_v.s Ton up Member

    Is the Euler Math Toolbox a good substitute for matlab??
    Any idea if it would help me??
     
  12. r_v.s

    r_v.s Ton up Member

    Would it help to use the Ryacas package???
     

Share This Page