Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Obsolete Editions Forum > C++ Programming with NR

Reply
 
Thread Tools Display Modes
  #1  
Old 07-21-2008, 10:59 AM
marcoos marcoos is offline
Registered User
 
Join Date: Jul 2008
Posts: 2
Problem with integration.

Hi, already tried few routines from GSL and it seems it doesn't work.

Function: 1/(x^2 - alpha^2)

Can anyone tell how to calculate that numerically.
Tried to do it by "hand" as well but no good results.

Cheers.
Reply With Quote
  #2  
Old 07-22-2008, 12:16 AM
davekw7x davekw7x is offline
Registered User
 
Join Date: Jan 2008
Posts: 453
Quote:
Originally Posted by marcoos View Post
...it doesn't work...
Huh? What doesn't work?

What, exactly, did you try? (What functions?)
What, exactly, did you feed the functions? (Integration limits? Value of alpha?)
What, exactly, did you expect to get?
What, exactly, did the rascally functions give you?
What, exactly, do you not understand about the difference between what you expected and what you got?

Quote:
Originally Posted by marcoos
...Tried to do it by "hand"...
Exactly the same questions: What calculations? Etc.


What, exactly, is your assignment?

Is it to calculate a particular value of integral (with given limits and alpha)?

Or is it to derive (or discover---by reading a calculus book) an analytical formula for the integration and apply it to a particular problem?

Or is it to discover which numerical methods might be appropriate (and successful) for a given problem by comparing numerical results with the analytical solution?

Or what?

Regards,

Dave
Reply With Quote
  #3  
Old 07-22-2008, 05:14 AM
marcoos marcoos is offline
Registered User
 
Join Date: Jul 2008
Posts: 2
Hi,

actually the function looks like this

[tex]
f(y,z) = \int^{\infty}_{-\infty} \left( \frac{2y}{x^2-y^2} \right) \frac{dx}{e^{x-z}+1}
[tex]

so you have always two singularities at +/-y.

Already tried to do simple sum getting symmetrically from both sides of singularities - but results are bad. Tried GSL integration: qags, qagp, qawc. - answer I got: bad integral behavior or integral is divergent, or slowly convergent

Cheers
Reply With Quote
  #4  
Old 07-22-2008, 10:59 AM
davekw7x davekw7x is offline
Registered User
 
Join Date: Jan 2008
Posts: 453
Quote:
Originally Posted by marcoos View Post
...actually the function looks like this...
That's a lot different from your first post.

The first part of your original question concerns numerical solutions, but how about looking at the function and seeing what to expect? I mean, even if your goal is an analytical solution, sometimes a numerical approach can give some insight, but you still have to think about things.

I see the product of two terms under the integral sign:

2y/(x^2-y^2)

and

1/(exp(x-z) + 1)

Let's just pick convenient values of y and z and see what it looks like. For example, let y = 1 and z = 0. You want to integrate from x = minus infinity to infinity.

Then the two product terms of the integrand are

2/(x^2 - 1)

and

1/(exp(x) + 1)

Now, without trying to come up with an analytic solution, you could note that the second term is pretty civilized (stays finite everywhere; approaches zero at one limit, approaches one at the other I think), but the first term has a non-integrable singularities at x = -1 and x = 1. (The function in your first post has non-integrable singularities at x = -alpha and x = alpha, right?)

What happens with your numeric attempts if you try integrate this specific product (with y = 1, z = 0) as you approach x = 1 from the left? Try it for, say, 0 to 0.9? How about 0 to 0.99? Etc.

Is it just possible that the function is not integrable over the interval minus infinity to infinity for these particular values of y and z? Are there any other values of y and z that make it behave differently (and, maybe, allow some additional insight)?

Or...maybe I'm missing something. (It wouldn't be the first time.)

Regards,

Dave
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:48 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.