
Heaviside Function

brazen_cur
Note: It's not the "true" Heaviside function, ie. the derivatives and integrals are not what you might expect, but it gets the job done.
Function Heaviside(xo) //+ Variable xo return p < xo ? 0 : 1 //+ End //Usage example: // // Make test_wave = Heaviside(0) // //or for a function that "switches off" at a given point: // // Variable cutoff_point = 5 // Make test_wave2 = x - x*Heaviside(cutoff_point) //

Forum

Support

Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
Then you would write your wave assignment like this:
Make test_wave = Heaviside(x, 0)
Make test_wave2 = x - x*Heaviside(x, cutoff_point)
A couple extra keystrokes, with the advantage that there are fewer surprises.
For instance, your function used like this:
print Heaviside(0)
will always return 1 because p returns 0 when there is no wave on the left side.
In fact, it's not hard to get the same functionality in an easy one-liner:
Make test_wave = x < 5
which works because in Igor, false is zero and true is 1.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
March 9, 2009 at 10:16 am - Permalink