Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differentiable approximation of the round() Matlab function

Could you possibly suggest a differentiable approximation for the round Matlab function?

The round function looks like this:

enter image description here

I would like a differentiable function which [closely] resembles the one in the figure.

like image 734
user92382 Avatar asked Nov 24 '25 10:11

user92382


2 Answers

You could write the derivative using the dirac delta - it's called 'dirac comb'.

Also you can write the round function as sum of the Heaviside step functions.

for both there are many approximations - just select a differentiable one.

like image 105
bdecaf Avatar answered Nov 27 '25 00:11

bdecaf


Well, y=x is differentiable and, if you stand far enough back, looks exactly like your target function. It does differ from round in that it maps reals to reals rather than reals to integers.

I don't think it makes sense to talk about the differentiability of functions from the reals to the integers for anything other than trivial functions such as f(r) = 1 for all r in Reals.

You can probably get something closer to the step function by a judicious choice of trigonometric function. For example, this

enter image description here

is a plot of sin(x)+x. If I had more time I could probably tweak it to pass through (k,k) for all integers k, but I haven't so I'll leave that to you or other passers-by.

like image 32
High Performance Mark Avatar answered Nov 27 '25 00:11

High Performance Mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!