From 76b1aadb9052611fe6f75f0d0877862492c071e1 Mon Sep 17 00:00:00 2001 From: Martin Donk Date: Mon, 30 Dec 2019 16:58:23 -0600 Subject: [PATCH] Update to nroots --- nerdamer.core.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/nerdamer.core.js b/nerdamer.core.js index 095148cb..f67d1f60 100644 --- a/nerdamer.core.js +++ b/nerdamer.core.js @@ -6956,13 +6956,14 @@ var nerdamer = (function (imports) { a = Symbol.unwrapPARENS(_.parse(symbol).toLinear()); b = _.parse(symbol.power); } - if(symbol.group === P) { + else if(symbol.group === P) { a = _.parse(symbol.value); b = _.parse(symbol.power); } if(a && b && a.group === N && b.group === N) { var _roots = []; + var parts = Symbol.toPolarFormArray(symbol); var r = _.parse(a).abs().toString(); //https://en.wikipedia.org/wiki/De_Moivre%27s_formula var x = arg(a).toString(); @@ -6976,9 +6977,23 @@ var nerdamer = (function (imports) { } return Vector.fromArray(_roots); } + else if(symbol.isConstant(true)) { + var sign = symbol.sign(); + var x = evaluate(symbol.abs()); + var root = _.sqrt(x); + + var _roots = [root.clone(), root.negate()]; + + if(sign < 0) + _roots = _roots.map(function(x) { + return _.multiply(x, Symbol.imaginary()); + }); + } else { - return Vector.fromArray([_.parse(symbol)]); + _roots = [_.parse(symbol)]; } + + return Vector.fromArray(_roots); } /** @@ -11534,3 +11549,7 @@ var nerdamer = (function (imports) { if ((typeof module) !== 'undefined') { module.exports = nerdamer; }; + + +var x = nerdamer('nroots(4+2i)'); +console.log(x.text()); \ No newline at end of file