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

Home » Public Forums » archive » Re: Help needed!!
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: Help needed!! [message #70497 is a reply to message #70496] Fri, 16 April 2010 12:19 Go to previous messageGo to previous message
bala murugan is currently offline  bala murugan
Messages: 23
Registered: April 2010
Junior Member
On Apr 16, 1:13 pm, Gray <grayliketheco...@gmail.com> wrote:
> On Apr 16, 2:06 pm, bala murugan <bala2...@gmail.com> wrote:
>
>
>
>
>
>> On Apr 16, 11:48 am, "R.G. Stockwell" <noem...@please.com> wrote:
>
>>> "bala murugan" <bala2...@gmail.com> wrote in message
>
>>> news:29ee4ec6-4803-44fd-aa5c-00fc0d2c9376@u21g2000yqc.google groups.com...
>
>>>> Hi people,
>
>>>> I am new to IDL. This is my first program in IDL. Can somebody point
>>>> out the errors in my code. I have been struggling to get it right.
>
>>>> CODE:
>
>>>> FUNCTION poissondist,fLambda,N
>>>> r = RANDOMU(SEED,1)
>>>> FOR j=1,N,1 DO BEGIN
>
>>> arrays are indexed from 0... N-1
>
>>>> x=poisson(j,fLambda)
>>>> if (x EQ r) THEN a[i]=j
>
>>> floating point numbers may never be exactly equal.
>>> Use a "if abs(x-r) lt 0.0001 then"   type of statement
>
>>> as others have pointed out, 'a' and  'i' do not exist here.
>>> i have no idea what you think "i" should be.
>>> For a you will need to allocate an array inside that function, like so:
>>>  FUNCTION poissondist,fLambda,N
>>>  a = fltarr(N)
>>>  r = RANDOMU(SEED,1)
>>>  FOR j=0,N-1 DO BEGIN
>>> .... etc....
>
>>>> ENDFOR
>>>> RETURN,a
>>>> END
>
>>>> In the above code, the function "poisson" was written by me. It is as
>>>> follows,
>
>>>> CODE:
>
>>>> FUNCTION poisson,a,b
>>>> x = (b^a)/(exp(b)*factorial(a))
>>>> RETURN,x
>>>> END
>
>>> in the future, you may want  to make sure a and b are passed in
>>> before executing that statement. for example:
>
>>> if n_elements(a) eq 0 then message,'missing a'
>>> if n_elements(b) eq 0 then message,'missing b'
>
>>> cheers,
>>> bob
>
>>> PS bonus info.
>
>>> Make sure that the code for
>>> FUNCTION poissondist,fLambda,N
>>> is in a file called poissondist.pro, and that it is in your IDL path.
>
>>> Also, make sure your function:
>>> FUNCTION poisson,a,b
>>> is in a file called poisson.pro, and that it is in your IDL path.
>
>> Guys, thanks  a lot for the info.
>
>> Sorry, I made a mistake while copying the code and pasting it:
>
>> CODE:
>
>> FUNCTION poissondist,fLambda,N
>> FOR i=1,N,1 DO BEGIN
>>         a = FLTARR(N)
>>         r = RANDOMU(SEED,1)
>>         FOR j=1,N,1 DO BEGIN
>>                 x=poisson(j,fLambda)
>>                 if abs(x-r) lt 0.0001 THEN a[i]=j
>>         ENDFOR
>> ENDFOR
>> RETURN,a
>> END
>
>> I also came across another method. But am not sure if it does the same
>> thing as mentioned in the summary that I made.
>
>> The thing that I came across is as follows,
>
>> FUNCTION poissondist, fLambda, N
>> data = RANDOMU(SEED,N,POISSON=fLambda)
>> RETURN,data
>> END
>
>> Can you please clarify if the second method does the same thing as the
>> first?
>
>> Thanks,
>> B
>
> The second method does what you're looking for, the first may or may
> not but is overly complicated.

Thanks Gray....

But I would be glad if I can make the first method work....

If you have any suggestions of doing the first method in a different
way, please let me know...

By the way, thanks a lot!!!
[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
Previous Topic: Re: GridData Conundrum
Next Topic: Comparison operators and floating-point errors

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

Current Time: Wed Oct 08 20:10:52 PDT 2025

Total time taken to generate the page: 0.00364 seconds