Matrix dimensions for double integration

3 views (last 30 days)
Dear All,
I greatly appreciate this if someone can comment on the following:
I am trying to take a double integral where the integrand is a function of another double integral. I have the below function for the integrand:
function psi_yz=Psi_yz(betha,alpha,e_0)
psi_yz=@(y,z) integral2(@(y0,z0) exp( (-1i/betha)*(y-y0).*(z-z0) )...
.*exp(-y0.^2).*( heaviside(-z0).*airy(-z0-e_0)+airy(-e_0)*heaviside(z0).*exp(-abs(z0)/alpha)),-inf,inf,-inf,inf);
end
So I give three parameters (betha, alpha and e_0) and got a function
psi=@(y,z)
I then try to take an integration over y and z:
Psi=Psi_yz(betha,alpha,e_0)
A=integral2(Psi,-1,1,-1,1)
I got the error that "Matrix dimensions must agree."
Can someone let me know what is wrong here and what can I do.
Thanks.

Answers (1)

Walter Roberson
Walter Roberson on 25 Feb 2019
You are doing an integral2() over a function that already has an integral2() inside it.
integral2() passes in arrays, so Psi will be passed arrays. Those will become y and z inside of the anonymous function psi_yz, to be used in the inner integral2() that will pass in its own arrays of varying sizes to become y0 and z0. You have y-y0 both of which are arrays created by two different layers of integral2() -- but there is no promise at all that integral2 will have passed the two the same size of array. Indeed, near the end of integration you can be certain that integral2 will not have passed the same sizes for the inner integral2(): integral2() uses smaller arrays as it finishes tightening up integration tolerances.
  2 Comments
Amin Hosseinkhani
Amin Hosseinkhani on 25 Feb 2019
Thank you for your commnet. Do you also have an idea how I can proceed with this?
Best.
Walter Roberson
Walter Roberson on 25 Feb 2019
You might perhaps be able to handle the situation with an arrayfun() call. The two arrays received by Psi will be of equal size, so you can
arrayfun(@(Y, Z) integral2(.... Y-y0).*(Z-z0)....,-inf,inf,-inf,inf), y, z)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!