[scilab-Users] Plot of Step Function

xavier roguiez xr at geo.hmg.inpg.fr
Sun Nov 2 12:35:02 CET 2008


Klaus Pieper a écrit :
> Hi,
>
> Trying out the example from from 
> http://www.scilab.org/doc/intro/node25.html
>
> -->deff('[x]=foo(y)','if y>0 then, x=1; else, x=-1; end')
> -->x=-1:0.1:1
> -->plot(x,foo(x))
>
> I would expect the graph of a step function jumping from -1 to 1 at 0. 
> Instead I get a constant function y == -1 for -1 <= x <= 1.
>
> What's going wrong?
>
> Klaus
>
This solution works :
-> deff('[y]=foo(x)','y=(x>0)-(x<=0)')
-->foo(21)
 ans  =
    1.
-->foo(-2)
 ans  =
  - 1.

-->foo(-2:1:2)
 ans  =
  - 1.  - 1.  - 1.    1.    1.

-->foo(x)
 ans  =column  1 to 11
  - 1.  - 1.  - 1.  - 1.  - 1.  - 1.  - 1.  - 1.  - 1.  - 1.  - 1.
        column 12 to 21
    1.    1.    1.    1.    1.    1.    1.    1.    1.    1.
-->plot(x,foo(x))


Xavier



More information about the users mailing list