# "lsqnonlin" constantly stopped for failing to integrate numerically

2 views (last 30 days)
Jurgen on 1 Oct 2014
Edited: Matt J on 3 Oct 2014
I numerically solving a system of equations. Some have integral equations, for which I am using "integral", since there is no definite integral. My problem is that in some iterations "lsqnonlin" stops and returns the following message:
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 2.0e+03. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
After a while the iterations continue running, but returns quickly to stop, delivering the same message.
What am I doing wrong ?, there is any way to fix it, maybe changing my integration method?

Mike Hosea on 3 Oct 2014
Is it possible that your problem is singular or highly oscillatory inside the interval of integration for some parameter values? I mean, well, this happens, and I'm not doing anything wrong:
> q = @(c)integral(@(x)cos(exp(c)*x),0,2*pi)
q =
@(c)integral(@(x)cos(exp(c)*x),0,2*pi)
>> q(5)
ans =
0.003496745772498
>> q(10)
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 3.6e-02. The integral may not
exist, or it may be difficult to approximate numerically to the requested accuracy.
> In funfun\private\integralCalc>iterateScalarValued at 372
In funfun\private\integralCalc at 75
In integral at 88
In @(c)integral(@(x)cos(exp(c)*x),0,2*pi)
ans =
9.682301680398093e-06
The problem is just hard. It is difficult to advise you how to proceed without knowing more about the problem. Would it be possible to supply a condensed example of one of the problem integrals that I could play with to figure out what is hard about it?

Matt J on 3 Oct 2014
Edited: Matt J on 3 Oct 2014
(integral(f,a,b))^2 --->0
to zero with lsqnonlin, maybe it would be enough to push samples of the integrand to zero on the interval [a,b]
sum([f(a), f(a+delta), f(a+2*delta),+...+f(b)]).^2 --->0
using some appropriate sampling interval length, delta. This way you circumvent the difficult integral altogether, or at least you effectively get a more direct hand in the sampling it uses.