Search code examples
matlabexponentialintegral

MATLAB: how to solve this integral for getting expected value?


I want to solve the expected value for f(x) with x=[x1,x2] follows uniform distribution. I tried this:

syms x r d x1 x2;
f=2*x*acos(x^2-d^2/2*x*(r+d)+d/x)*(1/sqrt(2*pi))*exp(-x^2/2);
int(f,'x',x1,x2)

I need a parametric approach. But Matlab fails to solve this integration in symbolic format. Any solution to that?


Solution

  • If you want to do it numerically, you need to use a numerical function: integral

    example:

    d=40;r=15;
    %define f as anonymous function 
    f=@(x)2.*x.*acos(x.^2-d^2./2.*x.*(r+d)+d./x).*(1/sqrt(2*pi)).*exp(-x.^2/2);
    integral(f,40,70)
    

    This gives me 0, (because it is 0), but if you try, for example:

    d=4;r=2
    integral(f,0,10)
    
    ans =
    
       2.4036 - 3.3624i