comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Compute area between curves
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Compute area between curves [message #63007 is a reply to message #62821] Fri, 17 October 2008 12:43 Go to previous messageGo to previous message
jameskuyper is currently offline  jameskuyper
Messages: 79
Registered: October 2007
Member
mystea wrote:
> Hi James,
>
> I would like to thank you for your reply. It is truly helpful.
>
> Here is an example:
>
> x=dindgen(200)+1
> y=x^(-2)

For this function, the second derivative f2 = 6*x^(-4). The sixth
derivative f6 = 5040*x^-8. Within the range of integration, the
maximum values of f2 and d6 both occur at x =1, so f2_max = 6 and
f6_max=5040. Therefore, the maximum step size for which INT_TABULATED
gives better results than TSUM is

(315*f2_max/(32*f6_max))^0.25 = 0.329

Your data is tabulated with a spacing of 1.0, which is more than 3
times too large to get better results with INT_TABULATED than with
TSUM. Try the following:

x = 0.25*dindgen(800)+1.0

You get much nicer results that way.

> q=dblarr(200)
> for i=1,199 do q[i]=int_tabulated(x[0:i],y[0:i])
>
> plot,q
> plot,y
> plot,deriv(y)
>
> plot,sort(q)
>
> x2=x
> x2[60:199]=x2[60]+x2[60]*dindgen(140)
> y2=x2^(-2)

For the second portion of your data, the spacing is 61 units. The
maximum values of f2 and f6 occur in that region occur at x = 61:

f2_max = 6*x[60]^(-4)
f6_max = 5040*x[60]^(-8)

For this portion of the data, the minimum step size needed is

(315*f2_max/(32*f6_max))^0.25 = 20.07

Once again, the spacing of your tabulated data is more than 3 times
too large for INT_TABULATED to give you better results than TSUM. The
moral of this story is that, if you can, you should sample your data
more closely. If you can't do that, you'll have to integrate it using
a more robust integration method, such as TSUM.


> q2=dblarr(200)
> for i=1,199 do q2[i]=int_tabulated(x2[0:i],y2[0:i])
> plot,q2
> plot,deriv(y2)

It would be more meaningful to use

plot, x2, q2
plot, x2, deriv(x2,y2)

However, give the range of values involved, you won't actually be able
to see anything on that second plot. For a more readable plot, use

plot, x2, -deriv(x2,y2), /xlog,/ylog

For comparison, the analytical result is:

oplot, x2, 2*x2^(-3)

Which seems to be a pretty accurate match.

...
> As you can see, the results of integration is wiggling here.
> It's not necessary that the polynomial goes negative, its
> probably just because the routine is using different polynomials when
> new terms are introduced.

No, the issue is that the best-fit polynomial for under-sampled data
isn't a particularly good fit. That polynomial has wiggles that don't
match the shape of the function actually being tabulated.

> I also figured out that the deriv routine went crazy under some
> circumstance, too.
> In these cases, deriv(y) should go to zero, yet it was oscillating
> crazy.

I didn't see any oscillations in deriv(y), or deriv(x2,y2). Could you
explain that more precisely?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Contour Issues... Help please
Next Topic: IDL User Group Meeting Huge Success: Correction

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 02:44:53 PDT 2025

Total time taken to generate the page: 0.71930 seconds