Algosim documentation: defuzz

defuzz

Replaces entries that are extremely close to being integral with the integers they approximate.

Syntax

Description

If x is a number, a vector, or a matrix, then defuzz(x, ε) returns x with all entries that are extremely close to being integral replaced by the integers they approximate. The required closeness is specified by the ε parameter, which defaults to 1E−8 if omitted.

Examples

A ≔ ❨❨4, 1, 2, 3❩, ❨0, −2, 1, 5❩, ❨1, 0, 2, 2❩, ❨6, 1, 0, 2❩❩
⎛ 4   1   2   3⎞
⎜ 0  −2   1   5⎟
⎜ 1   0   2   2⎟
⎝ 6   1   0   2⎠
Λ, U ≔ eigenvectors(A);
U ⋅ diag(Λ) ⋅ U^−1
⎛                    4 − 2.93249699516⋅10^−18⋅i                       1 − 6.7735386976⋅10^−19⋅i                      2 + 5.21897174135⋅10^−20⋅i                       3 + 5.6676363145⋅10^−21⋅i⎞
⎜−2.23074596989⋅10^−17 + 3.91940438539⋅10^−18⋅i                      −2 + 1.1917654819⋅10^−18⋅i                      1 − 2.81257201536⋅10^−18⋅i                       5 − 4.7883868275⋅10^−18⋅i⎟
⎜                    1 − 8.33908275002⋅10^−19⋅i   1.21972744405⋅10^−19 − 1.51585575754⋅10^−19⋅i                      2 − 3.33358238173⋅10^−19⋅i                      2 − 4.65069351146⋅10^−19⋅i⎟
⎝                    6 − 1.47707544878⋅10^−18⋅i                      1 − 1.22688894046⋅10^−19⋅i   5.96311194867⋅10^−19 − 8.62051771278⋅10^−19⋅i                      2 − 1.37030513329⋅10^−18⋅i⎠
defuzz(ans)
⎛ 4   1   2   3⎞
⎜ 0  −2   1   5⎟
⎜ 1   0   2   2⎟
⎝ 6   1   0   2⎠