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 #70503 is a reply to message #70502] Fri, 16 April 2010 10:48 Go to previous messageGo to previous message
R.G.Stockwell is currently offline  R.G.Stockwell
Messages: 163
Registered: October 2004
Senior Member
"bala murugan" <bala2305@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.
[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: Sat Oct 11 03:17:32 PDT 2025

Total time taken to generate the page: 1.20261 seconds