Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

Symbolic expression of `sng()` which isn’t zero at `sgn(0)`

asked 5 years ago

Dan-K gravatar image

sng(0) = 0 but I need a symbolic function or expression that evaluates to +1 or -1 as per the following definition:

side(u)={+1,if u01,if u<0

I’ve tried the following but each have their own problems:

side = sgn(u) # Evaluates to 0 at u = 0
side = u/abs(u) # “ValueError: power::eval(): division by zero” at u = 0
side = 1 - (u < 0)*2 # “TypeError: unable to simplify to float approximation”
# These next two use a Python expression so ‘u’ gets evaluated too early.
side = -1 if u < 0 else 1
side = lambda u: -1 if u < 0 else 1

Is there a way I can define this function symbolically?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 5 years ago

nbruin gravatar image
side(u) = sign(u) + kronecker_delta(u,0)

would do the trick ...

Preview: (hide)
link

Comments

1

You sweet genius

Dan-K gravatar imageDan-K ( 5 years ago )
2

answered 5 years ago

Juanjo gravatar image

As another option, you can define side as follows:

side(u) = 2*unit_step(u) - 1

Hence

sage: [side(a) for a in range(-2,3)]
[-1, -1, 1, 1, 1]
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 5 years ago

Seen: 415 times

Last updated: Feb 18 '20