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

Home » Public Forums » archive » QSIMP function
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
QSIMP function [message #85827] Thu, 12 September 2013 06:31 Go to next message
fd_luni is currently offline  fd_luni
Messages: 66
Registered: January 2013
Member
Instead of using the QSIMP function can I write the code as a summation and use also the Simpson's rule?
Re: QSIMP function [message #85828 is a reply to message #85827] Thu, 12 September 2013 07:56 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
You need to distinguish between 2 cases:

1. You know the function f(x) so that you can it evaluate it at any x. This is the type of problem that QSIMP is meant for. ( I prefer to use Craig Markwardt's QPINT1d http://cow.physics.wisc.edu/~craigm/idl/down/qpint1d.pro )

2. You have tabulated X,Y values but no functional form. Here you can do summation of trapezoids (as in
http://idlastro.gsfc.nasa.gov/ftp/pro/math/tsum.pro ). But if there is any continuity to your function at all, then I would try using INT_TABULATED .

--Wayne

On Thursday, September 12, 2013 9:31:49 AM UTC-4, fd_...@mail.com wrote:
> Instead of using the QSIMP function can I write the code as a summation and use also the Simpson's rule?
Re: QSIMP function [message #85829 is a reply to message #85828] Thu, 12 September 2013 08:40 Go to previous messageGo to next message
fd_luni is currently offline  fd_luni
Messages: 66
Registered: January 2013
Member
I used before the INT_TABULATED. I want to avoid to make a for loop that is why I am looking how can I make it with summation. You see what I mean?
Re: QSIMP function [message #85830 is a reply to message #85829] Thu, 12 September 2013 08:49 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Thursday, September 12, 2013 11:40:03 AM UTC-4, fd_...@mail.com wrote:
> I used before the INT_TABULATED. I want to avoid to make a for loop that is why I am looking how can I make it with summation. You see what I mean?

So you don't want the area under a curve, but you want to get the area (estimated by a trapezoid) covered by consecutive points. Then the code you posted earlier is fine.

I presume you have millions of points if you are worried about using a FOR loop.
Re: QSIMP function [message #85831 is a reply to message #85830] Thu, 12 September 2013 08:58 Go to previous messageGo to next message
fd_luni is currently offline  fd_luni
Messages: 66
Registered: January 2013
Member
> So you don't want the area under a curve, but you want to get the area (estimated by a trapezoid) covered by consecutive points. Then the code you posted earlier is fine.

The code for trapezoidal that I posted earlier it does not work very well, I have an underestimation because my data changes fast. That is why I am looking for an alternative method.

> I presume you have millions of points if you are worried about using a FOR loop.

Yeah because it takes me long time with a FOR loop.
Re: QSIMP function [message #85832 is a reply to message #85831] Thu, 12 September 2013 10:05 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
One suggestion for improved accuracy is to interpolate your function at the midpoints of all your tabulated X values. You can use one of the options (e.g. spline,least-squares quadratic) in the INTERPOL() function without needing a loop. Then redo your trapezoidal integration routines but using twice as many points, then rebin your final answer by a factor of two.


On Thursday, September 12, 2013 11:58:40 AM UTC-4, fd_...@mail.com wrote:
>> So you don't want the area under a curve, but you want to get the area (estimated by a trapezoid) covered by consecutive points. Then the code you posted earlier is fine.
>
>
>
> The code for trapezoidal that I posted earlier it does not work very well, I have an underestimation because my data changes fast. That is why I am looking for an alternative method.
>
>
>
>> I presume you have millions of points if you are worried about using a FOR loop.
>
>
>
> Yeah because it takes me long time with a FOR loop.
Re: QSIMP function [message #85833 is a reply to message #85832] Thu, 12 September 2013 11:01 Go to previous messageGo to next message
fd_luni is currently offline  fd_luni
Messages: 66
Registered: January 2013
Member
How can I use one of the options of INTERPOL() without a loop?

Also I don't understand what you mean to redo my trapezoidal routines using twice as many points
Re: QSIMP function [message #85856 is a reply to message #85832] Fri, 13 September 2013 22:44 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Thursday, September 12, 2013 1:05:05 PM UTC-4, wlandsman wrote:
> One suggestion for improved accuracy is to interpolate your function at the midpoints of all your tabulated X values. You can use one of the options (e.g. spline,least-squares quadratic) in the INTERPOL() function without needing a loop. Then redo your trapezoidal integration routines but using twice as many points, then rebin your final answer by a factor of two.

Wayne, Maria asked me about this privately. Does interpolation really improve the accuracy? My first impression would be that it might help, or it might hurt, depending on how well the interpolation routine chosen reflects the underlying nature of the curve being sampled. I don't have any good intuition about how well this works in practice.

Thanks,
Craig
Re: QSIMP function [message #85863 is a reply to message #85856] Sat, 14 September 2013 19:58 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
The point is to interpolate using values at three or more local points, rather than just approximating the curve through consecutive points as a straight line, which is what trapezoidal integration does. INT_TABULATED works by interpolating over 5 points (using cubic spline interpolation). But the OP said that INT_TABULATED was too slow, so I was offering a next step of refinement from trapezoidal integration without being as compute intensive as INT_TABULATED.

--Wayne

On Saturday, September 14, 2013 1:44:07 AM UTC-4, Craig Markwardt wrote:

> Wayne, Maria asked me about this privately. Does interpolation really improve the accuracy? My first impression would be that it might help, or it might hurt, depending on how well the interpolation routine chosen reflects the underlying nature of the curve being sampled. I don't have any good intuition about how well this works in practice.
>
>
>
> Thanks,
>
> Craig
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Widget programing - Please help!
Next Topic: The IDL library for Shuffled Complex Evolution (SCEUA)

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

Current Time: Wed Oct 08 15:05:47 PDT 2025

Total time taken to generate the page: 0.00500 seconds