pimath 0.0.64 → 0.0.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pi.js CHANGED
@@ -3444,6 +3444,7 @@ exports.Rational = Rational;
3444
3444
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3445
3445
  exports.Study = exports.TABLE_OF_SIGNS = exports.FUNCTION_EXTREMA = exports.ASYMPTOTE = exports.ZEROTYPE = void 0;
3446
3446
  const fraction_1 = __webpack_require__(506);
3447
+ const numexp_1 = __webpack_require__(735);
3447
3448
  var ZEROTYPE;
3448
3449
  (function (ZEROTYPE) {
3449
3450
  ZEROTYPE["ZERO"] = "z";
@@ -3572,6 +3573,8 @@ class Study {
3572
3573
  if (resultLine[pos] === 'z') {
3573
3574
  // It's a zero. Get the coordinates
3574
3575
  let x, y, zero = zeroes[i].exact, pt, xTex, yTex, pointType;
3576
+ // TODO: NumExp should parse something that isn't yet plotFunction
3577
+ let exp = new numexp_1.NumExp(this.fx.plotFunction);
3575
3578
  if (zero instanceof fraction_1.Fraction) {
3576
3579
  let value = zero, evalY = this.fx.evaluate(value);
3577
3580
  x = zero.value;
@@ -3581,7 +3584,7 @@ class Study {
3581
3584
  }
3582
3585
  else {
3583
3586
  x = zeroes[i].value;
3584
- y = this.fx.evaluate(zeroes[i].value).value;
3587
+ y = exp.evaluate({ x });
3585
3588
  xTex = x.toFixed(2);
3586
3589
  yTex = y.toFixed(2);
3587
3590
  }
@@ -3653,6 +3656,39 @@ class Study {
3653
3656
  tex += `\n\\end{tikzpicture}`;
3654
3657
  return tex;
3655
3658
  };
3659
+ this.drawCode = () => {
3660
+ // Function as string
3661
+ let code = `f(x)=${this.fx.plotFunction}`;
3662
+ // Asymptotes
3663
+ let i = 1;
3664
+ this.asymptotes.forEach(asymptote => {
3665
+ if (asymptote.type === ASYMPTOTE.VERTICAL) {
3666
+ code += `\nav_${i}=line x=${asymptote.zero.value}->red,dash`;
3667
+ i++;
3668
+ }
3669
+ else if (asymptote.type === ASYMPTOTE.HORIZONTAL) {
3670
+ code += `\nah=line y=${asymptote.fx.monoms[0].coefficient.value}->orange,dash`;
3671
+ }
3672
+ else if (asymptote.type === ASYMPTOTE.SLOPE) {
3673
+ code += `\nao=line y=${asymptote.fx.plotFunction}->red,dash`;
3674
+ }
3675
+ i++;
3676
+ });
3677
+ // Extremes
3678
+ for (let zero in this.derivative.extremes) {
3679
+ let extreme = this.derivative.extremes[zero];
3680
+ code += `\nM_${i}(${extreme.value.x},${extreme.value.y})*`;
3681
+ i++;
3682
+ }
3683
+ // Zeroes
3684
+ this.zeroes.forEach(zero => {
3685
+ if (zero.type === ZEROTYPE.ZERO) {
3686
+ code += `\nZ_${i}(${zero.value},0)*`;
3687
+ i++;
3688
+ }
3689
+ });
3690
+ return code;
3691
+ };
3656
3692
  this.fx = fx;
3657
3693
  this.makeStudy();
3658
3694
  return this;
@@ -3752,13 +3788,13 @@ exports.RationalStudy = void 0;
3752
3788
  const study_1 = __webpack_require__(996);
3753
3789
  const rational_1 = __webpack_require__(107);
3754
3790
  const fraction_1 = __webpack_require__(506);
3791
+ const polynom_1 = __webpack_require__(38);
3755
3792
  class RationalStudy extends study_1.Study {
3756
3793
  constructor(fx) {
3757
3794
  super(fx);
3758
3795
  return this;
3759
3796
  }
3760
3797
  makeZeroes() {
3761
- console.log('GETTING ZEROES');
3762
3798
  return this._getZeroes(this.fx);
3763
3799
  }
3764
3800
  ;
@@ -3788,6 +3824,7 @@ class RationalStudy extends study_1.Study {
3788
3824
  }
3789
3825
  }
3790
3826
  asymptotes.push({
3827
+ fx: null,
3791
3828
  type: Ztype,
3792
3829
  tex: tex,
3793
3830
  zero: zero,
@@ -3798,18 +3835,20 @@ class RationalStudy extends study_1.Study {
3798
3835
  // Sloped asymptote
3799
3836
  let NDegree = this.fx.numerator.degree(), DDegree = this.fx.denominator.degree();
3800
3837
  if (NDegree.isEqual(DDegree)) {
3801
- let H = this.fx.numerator.monomByDegree().coefficient.clone().divide(this.fx.denominator.monomByDegree().coefficient).tex;
3838
+ let H = this.fx.numerator.monomByDegree().coefficient.clone().divide(this.fx.denominator.monomByDegree().coefficient), Htex = H.tex;
3802
3839
  let { reminder } = reduced.euclidian();
3803
3840
  asymptotes.push({
3841
+ fx: new polynom_1.Polynom(H),
3804
3842
  type: study_1.ASYMPTOTE.HORIZONTAL,
3805
- tex: `y=${H}`,
3843
+ tex: `y=${Htex}`,
3806
3844
  zero: null,
3807
- limits: `\\lim_{x\\to\\infty}\\ f(x) = ${H}`,
3845
+ limits: `\\lim_{x\\to\\infty}\\ f(x) = ${Htex}`,
3808
3846
  deltaX: new rational_1.Rational(reminder, reduced.denominator)
3809
3847
  });
3810
3848
  }
3811
3849
  else if (DDegree.greater(NDegree)) {
3812
3850
  asymptotes.push({
3851
+ fx: new polynom_1.Polynom('0'),
3813
3852
  type: study_1.ASYMPTOTE.HORIZONTAL,
3814
3853
  tex: `y=0`,
3815
3854
  zero: null,
@@ -3821,6 +3860,7 @@ class RationalStudy extends study_1.Study {
3821
3860
  // Calculate the slope
3822
3861
  let { quotient, reminder } = reduced.euclidian();
3823
3862
  asymptotes.push({
3863
+ fx: quotient.clone(),
3824
3864
  type: study_1.ASYMPTOTE.SLOPE,
3825
3865
  tex: `y=${quotient.tex}`,
3826
3866
  zero: null,
@@ -3833,7 +3873,6 @@ class RationalStudy extends study_1.Study {
3833
3873
  ;
3834
3874
  makeDerivative() {
3835
3875
  let dx = this.fx.clone().derivative(), tos = this._getSigns(dx, this._getZeroes(dx), study_1.TABLE_OF_SIGNS.GROWS);
3836
- console.log(tos.factors.length, tos.signs.length);
3837
3876
  let result = this.makeGrowsResult(tos);
3838
3877
  tos.signs.push(result.growsLine);
3839
3878
  tos.extremes = result.extremes;