Based on my understanding, the issue in the code is due to the symbolic integration of the function 'fun_S_S'.
The function fun_S_S involves several components, including trigonometric functions, polynomial terms, and potentially complex products. And symbolic integration attempts to find an exact analytical solution, which can be infeasible for complex expressions.
So as a workaround, you can use matlabFunction which transforms the symbolic expression into a MATLAB function handle, allowing for efficient numerical evaluation.This can be followed by numerical integration using the integral2 function in MATLAB.
You can refer to the attached code snippet for better understanding:
fun_S_S(i,j)= 2*pi*(r.^2).*Gii.*Gii.*sin(theta).^2.*Total(i,j).*((0.5*sqrt(1/pi)).^2);
r_min=s*n_S*n_S/(n_S+n_S);
fun_S_S_numeric = matlabFunction(fun_S_S(i,j), 'Vars', [r, theta]);
Matrix_element(i,j) = integral2(fun_S_S_numeric, r_min, 1000, 0, pi);
To learn more about matlabFunction and integral2 functions in MATLAB, you can refer to the following documentations:
- https://www.mathworks.com/help/symbolic/sym.matlabfunction.html
- https://www.mathworks.com/help/matlab/ref/integral2.html
Happy Coding!