3
$\begingroup$

I'm wondering if there's a built-in way in Mathematica to take a function whose output values are continuous, and quantize it to produce a step function. For example, I have the function

f[x_, n_, h_] := ArcTan[(n x)/h]*180/Pi - ArcTan[((n - 1) x)/h]*180/Pi

which I would like to digitize so that it takes on values in the set {0, 5, ... , 25}. I've done some searching but can't find a good way to achieve this.

$\endgroup$
7
$\begingroup$

Yes, you can use Round. The second argument of Round is the quantization step.

Examples:

Plot[
 Round[Sin[x], 0.2],
 {x, 0, 2 Pi}
]

Mathematica graphics

Plot[
 Round[Sin[x], 0.2],
 {x, 0, 2 Pi},
 ExclusionsStyle -> Automatic
]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.