0
votes

Found a strange thing, while coding numerical integration for a custom function. The MATLAB manual says:

integral3 calls integral to integrate over xmin ≤ x ≤ xmax. It calls integral2 with the 'tiled' method to evaluate the double integral...

I've done proper (I think it is) vectorization of my function, so it takes a tiled input from integral3 and returns a proper array of values. Integration passes without errors, but the NaN value is returned by integration (although the integrated function itself always returns an array of complex numbers).

Along with that if I use integral (with 'ArrayValued' method) of integral2 (tiled method) of the same function, as the manual says integral3 does, the returned values are non-NaN, but complex numbers.

Any idea, where NaN's may come from?

1
Complex numbers are a bit tricky to integrate. Could I see your function and your attempt? If you think the function is too long to write here, do not worry, it will not do any harm. In case your function really is long I would redo the same integration with a simple but still representative function to confirm that the integration works correctly.patrik
Thanks, but it's hardly possible - the function employs a bunch of other subfunctions, but basically boils down to a multiple of two complex exponents, and anyway I've overcome the problem (which is kind of confusing again) by going from: integral3(@(x,y,z) F(x,y,z),x1,x2,y1,y2,z1,z2) to integral3(@(z,x,y) F(x,y,z),z1,z2,x1,x2,y1,y2)Mike
I see, good that you got it to work, is it ok if I vote to close the question? You can also consider to submit an answer and accept it, just to show that the problem is solved.patrik

1 Answers

0
votes

Not sure how it worked out, but changing the integration order from integral3(@(x,y,z) F(x,y,z),x1,x2,y1,y2,z1,z2) to integral3(@(z,x,y) F(x,y,z),z1,z2,x1,x2,y1,y2) solved the problem.