Problem with integration for WKB approximation

AI Thread Summary
The discussion revolves around challenges faced while integrating a specific mathematical function using MATLAB, particularly when dealing with nested integrals. The user encountered difficulties in solving an integral that involves a cosine function with an inner integral, which complicates numerical evaluation. Initially, the user sought a suitable integration method but struggled to find a function that could handle the double integral effectively. However, after some exploration, they discovered a solution by using the `quad` function. The approach involves evaluating the inner integral each time the outer integral requires a function value, allowing for a numerical solution despite some accuracy concerns. The user shared their code implementation, which demonstrates how to perform the nested integration effectively.
magimbu
Messages
2
Reaction score
0
problem with integration for WKB approximation in MATLAB

hi all,
i have been having troubles with getting MATLAB to solve the following problem (the language is not the MATLAB one, the functions are not solvable by the symbolic integration and i was trying to get one of the quad functions to do it)(r1,r2 are numbers):

int(function*cos(int(function2,rprime,r,r2)),r,r1,r2)

As you can see the problem is that inside the cosinues there is an integral that goes from r ( variable of the first integral) to r2, so i can t solve it numerically, because i need it in function of r in order to perform the big integral.

I thought a couple integral function would exist but i am not able to find any ( the doublequad only works if its only one function integreded twice).

I hope what i wrote cna be understood, and appreciate your help and time!
JN
 
Last edited:
Physics news on Phys.org
hi all,
i found the answer a couple hours ago, even if accuracy hasn t been the best, it is just now a matter of choosing the right integration algorithm withim matlab.
I have until now write it using quad, basically the principle is that every time the outside integration wants to evaluate the function at a certain point, i evaluate the inner integral starting at that point. i m posting my solution so maybe it can help somebody else, thanks for looking at my post. so the code looks like this:

solutionTest= quad((@integrand2),r1,r2)

% then here is integrand 2, the letters are global constants


function valor = integrand2(r)

% here i have to see how many steps there are and for each of those i do
% the numerical integration inside
steps1 = size(r);
steps = steps1(1,2);
i=1;
% and for each step i perform the integration

while i <steps+1

valores(i) = 1./(((Q-calculateVTotal1(r(i))).*2*reducedMass/(hbar^2)).^(1/2))*cos( quad((@integrand1),r(i),r2)).^2;
i=i+1;
end
valor = valores;

end
 
Back
Top