Heaviside Function
Posted March 6th, 2009 by brazen_cur
I'm not sure if this already exists, but here it is. Incredibly useful!
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) //

I would like to add a
I would like to add a caution: you have used the p function inside your function, so this function will only work correctly on the right side of a wave assignment. It is more usual to write such things this way:
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