There is a bug in MS in that a script including an if statement works when called from the command line but does not work correctly when called within a loop such as a table or a plot. An example of this is shown below. What is the status of fixing this bug?
Ok, thanks for letting us know. This seems to be a problem with user-defined functions, since built-in functions appear to work fine.
For this particular example I would use Table(Choose(x<0,2,x>=0,0),[x,-4,4,1],y).
Stephen
Shakey,
I accepted your answer too readily. The use of a built-in function (at least Choose) does not solve the problem. See below.
Table(Choose(Abs(x)<.0001,1,Abs(x)>=.0001,sin(x)/x),[x,-4,4,1],y). This gives the correct table values for all values of x other than zero, but returns error for that entry. However, if I define f(x)=Choose(Abs(x)<.0001,1,Abs(x)>=.0001,sin(x)/x) and compute f(0) then it computes correctly. And if with this definition I try to compute the the table Table[f(x),[x,-4,4,1],y) then I again get an error for x=0.
Name=sinc
Parameters=w
if(w==0)
g=1
else
g=sin(x)/x
end
g
Name=sinc
Parameters=w
if(abs(w)<.00010)
g=1
else
g=sin(x)/x
end
g
It looks like you're new here. If you want to get involved, click one of these buttons!