Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Numerically minimizing an expression involving an integral

Subject: Numerically minimizing an expression involving an integral

From: svampur

Date: 16 Jul, 2012 03:15:16

Message: 1 of 7

I need to numerically find the cutoff value x>0 such that the integral from x to infinity of a decreasing function f is equal to some value y. There does not exist a closed form solution for the integral.

What would be the best way to do this in Matlab? Speed is also important as I need to repeatedly solve this for different values of y.

Subject: Numerically minimizing an expression involving an integral

From: Nasser M. Abbasi

Date: 16 Jul, 2012 03:35:56

Message: 2 of 7

On 7/15/2012 10:15 PM, svampur wrote:

> I need to numerically find the cutoff value x>0 such that the integral from x to infinity

'infinity' and 'numerically' ?

It seems you need to do analytical analysis here because it is hard
to do numerical computation to infinity unless the numerical computation
happened to be smart enough to see that one is using "infinity" term
and then do something about it. Or designed to handle this case

There are numerical integrators that handle infinity limits, but
they are designed to do that. I do not think Matlab's do that
(I could be wrong, have not looked at the new ones).

either way, try to specify your problem in mathematical terms,
and see if you can analyze it analytically, you might find a
simple solution this way.

--Nasser

Subject: Numerically minimizing an expression involving an integral

From: svampur

Date: 16 Jul, 2012 04:15:43

Message: 3 of 7

I am using the 'int' function to do the integration.
For example I can define a function returning the integral from the cutoff value x to infinity in the following way:

banana = @(x) (double(int(function to be integrated, x, inf)));

Then I can use fminsearch, fminbnd, fzero or something to minimize (banana(x) - y)^2 to find the cutoff value x.

This is just too slow and can surely be done in a more efficient way.
    


"Nasser M. Abbasi" <nma@12000.org> wrote in message <ju026s$2ee$1@speranza.aioe.org>...
> On 7/15/2012 10:15 PM, svampur wrote:
>
> > I need to numerically find the cutoff value x>0 such that the integral from x to infinity
>
> 'infinity' and 'numerically' ?
>
> It seems you need to do analytical analysis here because it is hard
> to do numerical computation to infinity unless the numerical computation
> happened to be smart enough to see that one is using "infinity" term
> and then do something about it. Or designed to handle this case
>
> There are numerical integrators that handle infinity limits, but
> they are designed to do that. I do not think Matlab's do that
> (I could be wrong, have not looked at the new ones).
>
> either way, try to specify your problem in mathematical terms,
> and see if you can analyze it analytically, you might find a
> simple solution this way.
>
> --Nasser

Subject: Numerically minimizing an expression involving an integral

From: Nasser M. Abbasi

Date: 16 Jul, 2012 04:46:14

Message: 4 of 7

On 7/15/2012 11:15 PM, svampur wrote:
> I am using the 'int' function to do the integration.
> For example I can define a function returning the integral from the cutoff value x to infinity in the following way:
>
> banana = @(x) (double(int(function to be integrated, x, inf)));
>
> Then I can use fminsearch, fminbnd, fzero or something to minimize
>(banana(x) - y)^2 to find the cutoff value x.

You seem to be mixing things here. You can't do
double() on result of int as you showed it. You probably meant
something like

EDU>> syms x
EDU>> f=exp(-x);
EDU>> banana = @(x) (int(f, x, inf));
EDU>> banana(x)

ans =
exp(-x)

But the above is symbolic expression. So can't use
it with numerical functions you listed above such as
fzero

EDU>> fzero(banana(x),1)
Error using fzero (line 169)
If FUN is a MATLAB object, it must have an feval method.

EDU>> fzero(@exp,1)

ans =

  -925.8190

Why not find an expression for your I(x)=int(f(x),x..infinity) first,
as a spearate step, then make an m file for the I(x) you found above,
then use that with the other numerical matlab functions.

i.e. break the problem in 2 steps. First find I(x), then do
the numerical work as second step.

--Nasser

Subject: Numerically minimizing an expression involving an integral

From: Torsten

Date: 16 Jul, 2012 07:09:21

Message: 5 of 7

On 16 Jul., 05:15, "svampur " <svei...@purdue.edu> wrote:
> I need to numerically find the cutoff value x>0 such that the integral from x to infinity of a decreasing function f is equal to some value y. There does not exist a closed form solution for the integral.
>
> What would be the best way to do this in Matlab? Speed is also important as I need to repeatedly solve this for different values of y.

I think there is no faster way as to call "quadgk" in combination with
"fzero" if no closed-form solution of the integral exists.
Call "quadgk" in the function subroutine where you have to supply the
residual for "fzero" with the lower limit y suggested by fzero.

Best wishes
Torsten.

Subject: Numerically minimizing an expression involving an integral

From: Bruno Luong

Date: 16 Jul, 2012 07:23:07

Message: 6 of 7

"svampur" wrote in message <ju0104$gvj$1@newscl01ah.mathworks.com>...
> I need to numerically find the cutoff value x>0 such that the integral from x to infinity of a decreasing function f is equal to some value y. There does not exist a closed form solution for the integral.
>
> What would be the best way to do this in Matlab? Speed is also important as I need to repeatedly solve this for different values of y.

If you don't need high accuracy, it might be better not to integrate with quad() / fzero() at all. Use ODE solver, keep the integral value in integral point, then interpolate the value in between by spline interpolation of such.

Bruno

Subject: Numerically minimizing an expression involving an integral

From: Steven_Lord

Date: 17 Jul, 2012 16:55:43

Message: 7 of 7



"svampur " <sveinno@purdue.edu> wrote in message
news:ju04hf$sl7$1@newscl01ah.mathworks.com...
> I am using the 'int' function to do the integration. For example I can
> define a function returning the integral from the cutoff value x to
> infinity in the following way:
>
> banana = @(x) (double(int(function to be integrated, x, inf)));
> Then I can use fminsearch, fminbnd, fzero or something to minimize
> (banana(x) - y)^2 to find the cutoff value x.
> This is just too slow and can surely be done in a more efficient way.

In this case, try sticking to symbolic calculations through the whole
problem rather than mixing symbolic and numeric calculations.

x = sym('x');
upperLimit = sym('upperLimit');
f = x.^2;
theintegral = int(f, 0, upperLimit); % the integral will still depend on the
variable upperLimit
v = solve(theintegral - 17) % solve int(x^2, 0, U) = 17 for U

In this case you're probably looking for the real solution, which on my
machine was the first element in v:

int(f, 0, v(1))

and you should receive 17.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us