MATLAB Answers


Integral2 of a dot product

Asked by Neelima Dahal on 10 Aug 2018 at 21:18
Latest activity Commented on by Walter Roberson
on 12 Aug 2018 at 23:29

Below is what I have:

Z=@(x,y) x+1i*y;
T=@(x,y) ((sinh(pi/ha*(Z(x,y)-1i*ha/2))).^2);
E=@(x,y) conj(1i*pi*V/ha*1/(K_ka_p)*sqrt((TC-TA)./(T(x,y)-TA)));
E_conj=@(x,y) conj(E(x,y));
Int=@(x,y) dot(E(x,y),(E_conj(x,y)))

When I run the code, I get the error "Integrand output size does not match the input size." I can get integral2 of all the functions leading up to Int. Just the Int function results in error. Anyone out there knows how to resolve this issue? Thank you!


Sign in to comment.

1 Answer

Answer by Walter Roberson
on 11 Aug 2018 at 3:24

"Integrand, specified as a function handle, defines the function to be integrated over the planar region xmin ≤ x ≤ xmax and ymin(x) ≤ y ≤ ymax(x). The function fun must accept two arrays of the same size and return an array of corresponding values. It must perform element-wise operations."

Your E(x,y) and E_conj(x,y) parts appear to handle that okay, but when you dot() those two arrays you get a single result instead of element-wise computation. Perhaps you should just be using .* instead of dot()


Show 1 older comment

When I was testing your code, I used random values:

V = rand();
ha = rand();
K_ka_p  = rand();
TC = rand();
TA = rand();

all of which I assumed were scalars. If some of your values are non-scalar then if we knew the sizes we could probably figure out how to code the operations.

Your assumption is correct. In the equation Z = x+1i*y, x and y are vectors of any length.

For Z, the x and y are as passed in to E and E_conj, which in turn gets them from Int, which gets them from integral2().

integral2() passes arrays of arbitrary vector or 2D size (the size will vary according to the level of refinement integral2() thinks it currently needs.) integral2() expects element-by-element calculation as-if each point were calculated independently of each other point.

So to us it is not obvious what part you are expecting to be vectors that you dot together to produce a per-point value.

If one or more of V, ha, K_ka_p, TC, or TA were vectors then it could make sense.

Sign in to comment.