Clear Filters
Clear Filters

Nesting multidimensional integrals when the integrand has if-else statements

2 views (last 30 days)
Hi, I am trying to do a multidimensional nested integral of a function that has if-else conditions in it. I know how to do nesting of integrals but I don't understand why I am getting the following error. Please see the code below. My issue is that Matlab throws a "Could not complete in 10000 steps" error even if the integrand is simple and regular. Is there a way to avoid this? Thanks.
func1 = @(k,p,v)integrdef(k,p,v);
func2 = @(p)integral2(@(k,v)arrayfun(@(k,v)func1(k,p,v),k,v),0,5,0,3);
%Ignore this line %func3 = integral(func2,0,7,'ArrayValued',true) %Ignore this line
func2(2)
function integrout=integrdef(a,b,c)
if (a>2) && (b>1)
integr = a.*b.*c;
else
integr = 0;
end
integrout = integr;
end
The output is as follows:
>> UpSEplusVert_pureintra_calc1
Warning: Reached the maximum number of function
evaluations (10000). The result fails the
global error test.
> In integral2Calc>integral2t (line 129)
In integral2Calc (line 9)
In integral2 (line 106)
In UpSEplusVert_pureintra_calc1>@(p)integral2(@(k,v)arrayfun(@(k,v)func1(k,p,v),k,v),0,5,0,3)
In UpSEplusVert_pureintra_calc1 (line 15)
ans =
9.4496e+01
It gives nearly the correct answer but I'd like high precision i.e. low global error. The exact answer is 94.5 but I get 94.496 instead. My actual goal is to do a 4-D integral using "integral3" and "integral" nesting, but for simplicity I have created a model example above which is only 3-D and solved it using a nesting of "integral2" and "integral" for illustration. Thanks.

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!