Which are the alternative codes of heaviside() function?

19 visualizaciones (últimos 30 días)
Tufan
Tufan el 7 de Jun. de 2016
Comentada: GandaBerunda el 18 de Jun. de 2022
Which are the alternative codes of heaviside() function?

Respuesta aceptada

GandaBerunda
GandaBerunda el 16 de Jun. de 2022
Hi Tufan,
Instead of using the heaviside() function, you can define your own function with a simple if elseif ladder. If the parameter is less than 0, you can return 0, at equal to 0, return 0.5 and greater than 0 return 1.
Hope it helps.
  2 comentarios
Sam Chak
Sam Chak el 16 de Jun. de 2022
Sure @Tufan can learn to write a custom function. However, the heaviside() function also uses the if-else conditional statement. If you can write a conditional-free simple code that works similarly as the Heaviside function, then it will benefit the community.
GandaBerunda
GandaBerunda el 18 de Jun. de 2022
One simple approach without if else which I can think of is:
out=(x>0)+0.5*(x==0)
where out is the result, and x is the input

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Event Functions en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by