
"step"-function

mssmtrainee
Here, I just would like to create a step function wave that depends on x. I wonder why it displays 0 for both conditions? It shouldn't! Any help would be appreciated. Thanks!
#pragma rtGlobals=1 // Use modern global access method. Function CreatingBConeData() KillWaves/A Variable theta = 39.5 //Semi-included angle of cone (generally ~39.5 deg) Variable R = 40e-9 //radius of spherical tip Variable b = R*cos(theta*pi/180) Variable eta = 0.5 Variable hstar = (b^2)/(2.*R) Variable Stif = 1000 Make/N=(100,1) Phorce; SetScale/I x, 0, 1e-6, Phorce variable index for(index=0; index<100; index+=1) if(index<50) //if(x<0.5e-6) Phorce = (4/(3*(1-eta^2)))*sqrt(R)*Stif*x^1.5 elseif (index>50) //elseif(x>0.5e-6) Phorce = 0 endif endfor print hstar End.
You might want to read up on wave assignment. To do that, execute the following command on Igor's command line:
March 13, 2012 at 03:42 pm - Permalink
Another simple one-liner step-function is using just a logic multiplier factor:
You could also use (x<0.5e-6) as the multiplier. Note that if you don't really need Phorce defined as a 2D wave (albeit 100 by 1), you are probably better off with a 1D wave as shown.
March 14, 2012 at 08:02 am - Permalink
should be this:
Notice the use of "[index]" to set a particular point in the wave. You were setting every point in the wave each time through the loop.
I also changed your elseif to if because your code did nothing for index==50.
Even with my changes, I still get all zeros. If you change the complicated expression to 1, you will see that the basic logic is correct - you get a square wave. Thus I conclude that your expression is returning zero for all x.
March 14, 2012 at 09:51 am - Permalink
There is an "x" in the calculation of the Phorce value. That's why I used a ternary assignment in my original answer.
Here is code that uses the loop and gives the correct result:
March 14, 2012 at 10:32 am - Permalink
Note the second wave dimension; remember that Phorce was defined as a 2D wave by mssmtrainee. I agree with Adam about the ambiguous value of 'x' in the wave element assignment, but it somehow seems to work with this version. Perhaps the 'index' value forces the proper scaled assignment of 'x' without explicit use of pnt2x().
March 14, 2012 at 10:53 am - Permalink
Since this is a 1D application, a 1D wave should be created. So this:
should be changed to:
March 14, 2012 at 02:40 pm - Permalink
March 15, 2012 at 11:50 am - Permalink