Why does integral2 function changes the array size of variable over which integration is performed?
5 views (last 30 days)
I am using the following command to integrate the function 'fun' with respect to s and t.
X = integral2(fun,0,s_max, 0, t_max, 'method','iterated');
While integrating the size of s and t is taken as 45x1 but sometimes it becomes 30x1. Why the size of integrating variables changes? Whenever the size becomes 30x1 the result of integration is very large abnormal value of power 10^90.
Mike Hosea on 14 Apr 2015
The iterated mode uses adaptive quadrature in each dimension, though your integrand function will, in a sense, be aware of only the inner integral. The length of the array is a function of the number of subintervals needing refinement, and in typical problems varies. With iterated integration it may not vary much if the initial mesh is already fine enough. Your observation that an incorrect result is associated with a certain size is not relevant, except insofar as it may indicate that a mesh refinement was needed. As Roger says, help us out with some more information about your problem, and perhaps we can tell you what the issue really is.
More Answers (1)
Roger Stafford on 13 Apr 2015
Where you say "While integrating the size of s and t is taken as 45x1 but sometimes it becomes 30x1" , you are apparently referring to the array sizes of s and t which are being sent to your 'fun' integrand function. That is characteristic of many integration routines and the integrand functions must be written so as to properly handle any size array that is sent to them. You can read about this at:
This has nothing to do with the size of your integration result, which is determined by the integrand function along with the two sets of integration limits. If you obtained 10^90, look at your integrand to see why.
If you want more detailed information, you should show us how your 'fun' and the four integration limits are defined.