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

Home » Public Forums » archive » Looking for more ideas on code ...
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Looking for more ideas on code ... [message #32276] Mon, 30 September 2002 13:26 Go to previous message
jeyadev is currently offline  jeyadev
Messages: 78
Registered: February 1995
Member
I have a question about how best (style and function, if possible!) to
write code for a function that has limits that have to be treated in a
special way. Consider the function

f(x) = sin(x)/x

as an example. Now, if x is always a scalar, then on just tests to see
if it is zero, and then handle that special case using a if .. then ..
else construct. But, what if x can also be scalar? I have the following
code that works:

------------------------------------------

function sinc, y


if(n_elements(y) eq 1) then begin ; y is a scalar
if(y eq 0.0) then profile = 1.0 else begin
profile = sin(y)/y
endelse
endif else begin ; y is a vector
zeros = where(y eq 0.0, ind)
if(ind gt 0) then y(zeros) = 1.0e-10 ; set zeroes to a small quantity
profile = sin(y)/y
endelse

profile = profile*profile/a0


return, profile

end

------------------------------------------

I guess the one can always set

profile(zeros) = 1.0

to handle the more general cases. But, the real question is there
a better way than

zeros = where(y eq 0.0, ind)
if(ind gt 0) then y(zeros) = "special values"
notzeros = where(y ne 0.0, ind)
if(ind gt 0) then y(notzeros) = "general definition"

I do understand that one should not compare reals, etc., but I will
clean up the numerics later.

thanks
sj

--

Surendar Jeyadev jeyadev@wrc.xerox.bounceback.com

Remove 'bounceback' for email address
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: ROI application...
Next Topic: Re: Array comparison

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

Current Time: Fri Oct 10 04:51:47 PDT 2025

Total time taken to generate the page: 0.28589 seconds