How to do Integration in R?

Q1: I do a simple integration below in Octave and wanna do it in R as well, not sure how though. R's integrate(f,from,to) doesn't have a "with respect to" argument, please advise.

Q2: For the f below, say it is a joint pdf (0<x,y <inf) and I wanna get P(X<Y) such that I first integrate f with respect to x from 0 to y, then with respect to y from 0 to inf. int(f,x,0,y) doesn't work.

Q3: Also, in Octave, how do you do multiple integration at once?

Code:
pkg load symbolic
syms x y
f = 2*exp(-x)*exp(-2*y);
int(f,x,1,inf); #integrate with respect to x
int(ans,y,0,1); #integrate with respect to y


#f is a pdf with <0,x,y<inf
#P(X<Y) is 1/3
int(f,x,0,y) #doesn't work
 
Last edited:
For Q2 I asked above, I did it a follows, but please let me know if there is a better/cleaner way to do it.

f.gif


Code:
>> pkg load symbolic #octave
>> syms x y
>> f = 2*exp(-x)*exp(-2*y); #joint pdf, 0<x,y<inf
>> antif = int(f,x); #antiderivative of f with respect to x
>> g = subs(antif,x,y) - subs(antif,x,0); #integrating f with respect to x from 0 to y equivalent
>> int(g,y,0,inf); #now integrating with respect to y from 0 to inf
>> ans
ans = (sym) 1/3
 
Last edited:
what is there to integrate in trading?

A price minus it's moving average is a differential. You can integrate differentials...

Even a price can be a differential (of prices). Lots of reasons to integrate.
 
Back
Top