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

Home » Public Forums » archive » Re: Fun with Int_tabulated.pro
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: Fun with Int_tabulated.pro [message #68472] Mon, 02 November 2009 06:15 Go to previous message
pgrigis is currently offline  pgrigis
Messages: 436
Registered: September 2007
Senior Member
On Oct 31, 10:12 am, Jeremy Bailin <astroco...@gmail.com> wrote:
> On Oct 30, 1:20 pm, wlandsman <wlands...@gmail.com> wrote:
>
>
>
>> I ran into a couple of gotchas with int_tabulated.pro this
>> morning,     It performs numerical integration for the simple case:
>
>> IDL> x = findgen(5)
>> IDL> y  = x^2
>> IDL> print,int_tabulated(x,y)
>> 21.3333
>
>> But if one has flipped  both vectors (say while converting wavelength
>> to frequency), then -- even though a plot of the two vectors looks
>> exactly the same -- int_tabulated gives a different answer.
>
>> IDL> x = reverse(x) & y = reverse(y)
>> IDL> print,int_tabulated(x,y)
>> 42.3619
>
>> A closer look at the int_tabulated documentation tells us that if X if
>> not monotonic increasing, then one needs to set the /SORT keyword.
>> So now we follow the documentation:
>
>> IDL> print,int_tabulated(x,y,/sort)
>> 21.3333
>
>> and get the right answer again.   But as the documentation also "sort"
>> of warns
>> you, setting the /SORT keyword reorders the input X and Y variables.
>> This is
>> probably not a problem unless one has modified the Y vector on the fly
>> by
>> some factor f
>
>>  f = findgen(5) + 0.5
>>  print,int_tabulated(x, y*f,/sort)
>
>> Upon output, the X vector has been sorted, but the Y vector has not,
>> since it
>> was passed as part of  a temporary variable y*f.    So one has lost
>> the one to
>> one correspondence between X and Y, screwing up all subsequent
>> processing.
>
>> --Wayne
>
> It looks ridiculous, but here's a workaround:
>
> print, int_tabulated(x+0, y*f, /sort)

I was looking at that thinking - yes, I see why that would help...
I feel an IDL hangover coming up :)

Ciao,
Paolo

Hint for the less addicted: issue help,x and
help,x+0 to see the subtle difference

>
> -Jeremy.
[Message index]
 
Read Message
Read Message
Previous Topic: Set Intersection Code
Next Topic: Re: weird contour lines

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

Current Time: Fri Oct 10 06:25:35 PDT 2025

Total time taken to generate the page: 0.16471 seconds