trying to use the following code to evaluate a triple integral which is a function of q,u. getting the error,
Warning: Maximum function count exceeded; singularity likely.
In quad at 107
In test1>Inner at 12
In test1>@(x)Inner(x) at 5
In quad at 76
In test1 at 5
Does anyone know what’s wrong with this code?
function [r] = test1(q,u)
b = u;
r = zeros(1);
for i = 1 : length(q);
r(i) = quad(@(x)Inner(x),-2,q);
end;
function [w] = Inner(k)
w = zeros(1);
for i = 1 : length(k);
w(i) = quad(@(n)InnerIntegral(n).*unifpdf(k(i)-n,-1,1),0,k(i)-1,k(i)+1);
end;
function [y] = InnerIntegral(n)
y = zeros(1);
for i = 1 : length(n);
y(i) = quad(@(m)unifpdf(n(i)-m, -b, b).*unifpdf(m,-b,b), n(i)-b,n(i)+b);
end;
end
end
end
When you define multiple functions like this, each function’s
endstatement must precede the next call tofunction. Currently, it looks like this is one giant function with a subfunction calledInnerand that subfunction has yet another subfunction calledInnerIntegral. Sotest1is trying to callInner, but`Inner‘s definition doesn’t occur until later inside of the definition oftest1.