Why do I receive a "Singularity likely" warning when I use the QUAD function in MATLAB
1 view (last 30 days)
Show older comments
Ebrahim Tofighi niaki
on 18 Dec 2014
Edited: Ebrahim Tofighi niaki
on 19 Dec 2014
For example when I execute the following command:
for i=1:10
for j=1:10
K(i,j)=quad('func',0,1,[],[],i,j);
end
end
function k=func(x,i,j)
B=[4.73 7.905 11 14.14 17.28 20.42 23.56 26.72 29.86 32.98];
k=(B(i)*(-sin(B(i)*x)+sinh(B(i)*x)-((cos(B(i))-cosh(B(i)))/((sin(B(i))-sinh(B(i)))))*(cos(B(i)*x)+cosh(B(i)*x)))).*(B(j)*(-sin(B(j)*x)+sinh(B(j)*x)-((cos(B(j))-cosh(B(j)))/((sin(B(j))-sinh(B(j)))))*(cos(B(j)*x)+cosh(B(j)*x))));
I receive the following warning message:
Warning: Maximum function count exceeded; singularity likely
what is the problem?
0 Comments
Accepted Answer
John D'Errico
on 19 Dec 2014
One problem is you have provided us with code for func, but you have quad calling sunc. I imagine that would leave MATLAB "singularly" confused. :)
OK, so assuming you simply cannot type well, look at your function. I'll modify it to be a function handle. I also changed some of the operators from * to .* and / to ./, just to be careful.
B=[4.73 7.905 11 14.14 17.28 20.42 23.56 26.72 29.86 32.98];
k = @(x,i,j) (B(i)*(-sin(B(i)*x)+sinh(B(i)*x)-((cos(B(i))-cosh(B(i)))./((sin(B(i))-sinh(B(i))))).*(cos(B(i)*x)+cosh(B(i)*x)))).*(B(j)*(-sin(B(j)*x)+sinh(B(j)*x)-((cos(B(j))-cosh(B(j)))./((sin(B(j))-sinh(B(j))))).*(cos(B(j)*x)+cosh(B(j)*x))));
So see what happens when you try to do the integration. Here, I plot each function as well as integrate it.
for i = 1:10
for j = 1:10
disp([i,j,integral(@(x) k(x,i,j),0,1,'RelTol',1e-10)])
ezplot(@(x) k(x,i,j),[0 1])
pause
end
end
These are sufficiently oscillatory functions, with what appears to be a fair amount of subtractive cancellation involved for larger i and j, that numerical integration tools end up with problems.
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!