Skip to content

Commit

Permalink
two numerical bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
istefanis committed Feb 2, 2024
1 parent c4cd07a commit 4443730
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion math/computerAlgebra/dataTypes/reals.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Math / ComputerAlgebra / DataTypes / Reals
*/

import { isZeroWithinTolerance } from "../../../util/commons.js";
import { set } from "../algebraicOperations.js";

/**
Expand All @@ -21,7 +22,7 @@ export const loadRealsOperations = function () {

//BUGFIX
set(["negate", "real"], (x) => -x);
set(["isZero", "real"], (x) => x === 0);
set(["isZero", "real"], (x) => isZeroWithinTolerance(x));

set(["gcd", "real", "real"], (a, b) => gcdReals(a, b));

Expand Down
4 changes: 4 additions & 0 deletions util/commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const roundDecimal = function (x, digits) {
return +x.toFixed(digits);
};

export const isZeroWithinTolerance = function (x) {
return Math.abs(x) < 10 ** -10;
};

//
// Polynomial
//
Expand Down
8 changes: 6 additions & 2 deletions view/plots/nyquistPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ export default class NyquistPlot {
// const minImag = Math.min(...imags);
// const maxImag = Math.max(...imags);

//set limits for coordinates of plotted points
const xMax = 10 ** 4;
const yMax = 10 ** 4;

//create the plot
const nyquistPlot = functionPlot({
target: `#${this.#nyquistPlotDomElement.id}`,
Expand All @@ -196,15 +200,15 @@ export default class NyquistPlot {
// },
{
points: this.#curvePoints
.filter((x) => x[0] > 0)
.filter((x) => x[0] > 0 && x[1] < xMax && x[2] < yMax)
.map((x) => [x[1], x[2]]),
// color: "red",
fnType: "points",
graphType: "polyline",
},
{
points: this.#curvePoints
.filter((x) => x[0] < 0)
.filter((x) => x[0] < 0 && x[1] > -xMax && x[2] > -yMax)
.map((x) => [x[1], x[2]]),
fnType: "points",
graphType: "polyline",
Expand Down

0 comments on commit 4443730

Please sign in to comment.