dimanche 3 novembre 2019

Writing a piecewise function inside deff

I am using deff to define piecewise functions in Scilab. I use if-else statements to define the function in different intervals. All of them seem to work except for this one.

This is my approach:

deff('a=f(p)', ["if(q >= -2 & q <= -1) then"; "a=1"; "elseif(q >= 1 & q <= 2) then"; "a=-1"; "else"; "a=0"; "end";])

The same approach worked on similar functions such as this.

eff('a=f(p)', ["if((p > 0 & p <= 2)) then"; "a=p/2"; "else"; "a=0"; "end";])

I have defined q as so:

q = -3:Ts:3;

where Ts is some floating point number. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire