Clear Filters
Clear Filters

Integration using Green's function in MatLab

14 views (last 30 days)
I have an integration
phi(r)= int_0^{inf} (r'^2 * dr' * G(r,r') * S(r'))
where G(r,r') = 1/(2*m*r*r')*(exp(-m*(r-r')) - exp(-m*(r+r'))) and S(r') is a known dataset at each r' and m is also known.
How to deal with this integration to find phi(r). Could you please help me on this?

Accepted Answer

Shubh Pareek
Shubh Pareek on 12 Jun 2023
From what i have understood you want to integrate phi function from 0 to infinity , may be this code can help
also since I didn't know what your dataset function S is so i specified it to be rprime itself.
m = 1; % Some constant value
r = 0.5; % Value of r to evaluate
% Define the function handles for G and S
G = @(r, rprime) 1./(2.*m.*r.*rprime).* (exp(-m.*(abs(r-rprime))) - exp(-m.*(r+rprime)));
S = @(rprime) rprime;% Define your dataset function here
% Define the integrand function
integrand = @(rprime) (rprime.^2) .* G(r, rprime) .* S(rprime);
% Evaluate the integral using MATLAB's integral function
phi_r = integral(integrand, 0, Inf)
phi_r = 2.0739
If you want to know more about integration with multiple variable or how integral function works here are some resources .
  2 Comments
Torsten
Torsten on 12 Jun 2023
I think a function of r for phi is more adequate here:
m = 1; % Some constant value
% Define the function handles for G and S
G = @(r, rprime) 1./(2.*m.*r.*rprime).* (exp(-m.*(abs(r-rprime))) - exp(-m.*(r+rprime)));
S = @(rprime) rprime;% Define your dataset function here
% Define the integrand function
integrand = @(r, rprime) (rprime.^2) .* G(r, rprime) .* S(rprime);
% Evaluate the integral using MATLAB's integral function
phi_r = @(r) integral(@(rprime)integrand(r, rprime), 0, Inf);
phi_r(0.5)
ans = 2.0739
pritha
pritha on 12 Jun 2023
Thanks for your reply @Shubh. I was not taking the abs(r-rprime). That's why I couldn't able to solve it. Thanks for helping me out. Thanks @Torsten for your reply. I am getting the result properly now.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!