How to perform indefinite integration of this function in MATLAB?

1.1k views Asked by At

I need to perform the following operations as shown in the image. I need to calculate the value of function H for different inputs(x) using MATLAB.

enter image description here

I am giving the following command from Symbolic Math Toolbox

syms y t x;
f1=(1-exp(-y))/y;
f2=-t+3*int(f1,[0,t]);
f3=exp(f2);
H=int(f3,[0,x]);

but the value of 2nd integral i.e. integral in the function H can't be calculated and my output is of the form of

H =

int(exp(3*eulergamma - t - 3*ei(-t) + 3*log(t)), t, 0, x)

If any of you guys know how to evaluate this or have a different idea about this, please share it with me.

1

There are 1 answers

2
Sardar Usama On BEST ANSWER

Directly Finding the Numerical Solution using integral:

Since you want to calculate H for different values of x, so instead of analytical solution, you can go for numerical solution.

Code:

syms y t;
f1=(1-exp(-y))/y;   f2=-t+3*int(f1,[0,t]);  f3=exp(f2);
H=integral(matlabFunction(f3),0,100)   % Result of integration when x=100 

Output:

H =
   37.9044

Finding the Approximate Analytical Solution using Monte-Carlo Integration:

It probably is an "Elliptic Integral" and cannot be expressed in terms of elementary functions. However, you can find an approximate analytical solution using "Monte-Carlo Integration" according to which:

Monte-Carlo Formula
where f(c) = 1/n Σ f(xᵢ)

Code:

syms x y t;

f1=(1-exp(-y))/y;   f2=-t+3*int(f1,[0,t]);  f3=exp(f2);
f3a= matlabFunction(f3);       % Converting to function handle

n = 1000;      
t = x*rand(n,1);               % Generating random numbers within the limits (0,x)
MCint(x) = x * mean(f3a(t));   % Integration
H= double(MCint(100))          % Result of integration when x=100  

Output:

H =
   35.2900

% Output will be different each time you execute it since it is based
% on generation of random numbers

Drawbacks of this approach:

  1. Solution is not exact but approximated.
  2. Greater the value of n, better the result and slower the code execution speed.

Read the documentation of matlabFunction, integral, Random Numbers Within a Specific Range, mean and double for further understanding of the code(s).