pimath 0.0.63 → 0.0.66

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.
@@ -8,6 +8,7 @@ import {ISolution} from "./equation";
8
8
  import {Polynom} from "./polynom";
9
9
  import {Fraction} from "../coefficients/fraction";
10
10
  import {Point} from "../geometry/point";
11
+ import {NumExp} from "../expressions/numexp";
11
12
 
12
13
  export type StudyableFunction = Rational
13
14
 
@@ -31,11 +32,13 @@ export enum ASYMPTOTE {
31
32
  }
32
33
 
33
34
  export interface IAsymptote {
35
+ fx: Polynom,
34
36
  deltaX: StudyableFunction
35
37
  limits: string,
36
38
  tex: string,
37
39
  type: ASYMPTOTE,
38
40
  zero: IZero,
41
+ tableOfSign: ITableOfSigns
39
42
  }
40
43
 
41
44
  export enum FUNCTION_EXTREMA {
@@ -65,6 +68,7 @@ export interface ITableOfSigns {
65
68
  signs: (string[])[],
66
69
  type: TABLE_OF_SIGNS
67
70
  zeroes: IZero[],
71
+ tex: string
68
72
  }
69
73
 
70
74
  export enum TABLE_OF_SIGNS {
@@ -122,7 +126,7 @@ export class Study {
122
126
  return this._derivative;
123
127
  }
124
128
 
125
- get tex(): string {
129
+ get texSigns(): string {
126
130
  return this._makeTexFromTableOfSigns(this._signs)
127
131
  }
128
132
 
@@ -144,6 +148,11 @@ export class Study {
144
148
  this._derivative = this.makeDerivative()
145
149
 
146
150
  this._variations = this.makeVariation()
151
+
152
+ this._signs.tex = this.texSigns
153
+ this._derivative.tex = this.texGrows
154
+ this._variations.tex = this.texVariations
155
+
147
156
  };
148
157
 
149
158
  indexOfZero = (zeroes: IZero[], zero: IZero | ISolution): number => {
@@ -223,7 +232,7 @@ export class Study {
223
232
  return resultLine
224
233
  }
225
234
 
226
- makeGrowsResult = (fx: StudyableFunction, tos: ITableOfSigns): { growsLine: string[], extremes: { [Key: string]: IExtrema } } => {
235
+ makeGrowsResult = (tos: ITableOfSigns): { growsLine: string[], extremes: { [Key: string]: IExtrema } } => {
227
236
 
228
237
  // Use the last line (=> resultLine) to grab the necessary information
229
238
  let signsAsArray = Object.values(tos.signs),
@@ -245,9 +254,12 @@ export class Study {
245
254
  xTex: string, yTex: string,
246
255
  pointType: FUNCTION_EXTREMA
247
256
 
257
+ // TODO: NumExp should parse something that isn't yet plotFunction
258
+ let exp = new NumExp(this.fx.plotFunction)
259
+
248
260
  if (zero instanceof Fraction) {
249
261
  let value: Fraction = zero,
250
- evalY = fx.evaluate(value)
262
+ evalY = this.fx.evaluate(value)
251
263
 
252
264
  x = zero.value
253
265
  y = evalY.value
@@ -255,7 +267,7 @@ export class Study {
255
267
  yTex = evalY.tex
256
268
  } else {
257
269
  x = zeroes[i].value
258
- y = fx.evaluate(zeroes[i].value).value
270
+ y = exp.evaluate({x})
259
271
 
260
272
  xTex = x.toFixed(2)
261
273
  yTex = y.toFixed(2)
@@ -298,7 +310,7 @@ export class Study {
298
310
  return {growsLine, extremes}
299
311
  }
300
312
 
301
- makeVariationsResult = (fx: StudyableFunction, tos: ITableOfSigns): { varsLine: string[], extremes: { [Key: string]: IExtrema } } => {
313
+ makeVariationsResult = (tos: ITableOfSigns): { varsLine: string[], extremes: { [Key: string]: IExtrema } } => {
302
314
  // TODO: make variations result is not yet implemented.
303
315
  let extremes = {},
304
316
  varsLine: string[] = []
@@ -316,7 +328,8 @@ export class Study {
316
328
  factors: [],
317
329
  zeroes: [],
318
330
  signs: [],
319
- extremes: {}
331
+ extremes: {},
332
+ tex: ''
320
333
  }
321
334
  };
322
335
 
@@ -331,7 +344,8 @@ export class Study {
331
344
  factors: [],
332
345
  zeroes: [],
333
346
  signs: [],
334
- extremes: {}
347
+ extremes: {},
348
+ tex: ''
335
349
  }
336
350
  }
337
351
 
@@ -342,7 +356,8 @@ export class Study {
342
356
  factors: [],
343
357
  zeroes: [],
344
358
  signs: [],
345
- extremes: {}
359
+ extremes: {},
360
+ tex: ''
346
361
  }
347
362
  }
348
363
 
@@ -381,4 +396,41 @@ export class Study {
381
396
 
382
397
  return tex
383
398
  }
399
+
400
+ drawCode = (): string => {
401
+ // Function as string
402
+ let code = `f(x)=${this.fx.plotFunction}`
403
+
404
+ // Asymptotes
405
+ let i: number = 1
406
+ this.asymptotes.forEach(asymptote => {
407
+ if (asymptote.type === ASYMPTOTE.VERTICAL) {
408
+ code += `\nav_${i}=line x=${asymptote.zero.value}->red,dash`
409
+ i++
410
+ } else if (asymptote.type === ASYMPTOTE.HORIZONTAL) {
411
+ code += `\nah=line y=${asymptote.fx.monoms[0].coefficient.value}->orange,dash`
412
+ } else if (asymptote.type === ASYMPTOTE.SLOPE) {
413
+ code += `\nao=line y=${asymptote.fx.plotFunction}->red,dash`
414
+ }
415
+ i++
416
+ })
417
+
418
+ // Extremes
419
+ for (let zero in this.derivative.extremes) {
420
+ let extreme = this.derivative.extremes[zero]
421
+
422
+ code += `\nM_${i}(${extreme.value.x},${extreme.value.y})*`
423
+ i++
424
+ }
425
+
426
+ // Zeroes
427
+ this.zeroes.forEach(zero => {
428
+ if (zero.type === ZEROTYPE.ZERO) {
429
+ code += `\nZ_${i}(${zero.value},0)*`
430
+ i++
431
+ }
432
+ })
433
+
434
+ return code
435
+ }
384
436
  }
@@ -1,6 +1,8 @@
1
1
  import {describe} from "mocha";
2
2
  import {Rational} from "../../src/maths/algebra/rational";
3
3
  import {RationalStudy} from "../../src/maths/algebra/study/rationalStudy";
4
+ import {expect} from "chai";
5
+ import {ASYMPTOTE} from "../../src/maths/algebra/study";
4
6
 
5
7
  describe('Study tests', () => {
6
8
  it('should get the zeroes', function () {
@@ -9,10 +11,33 @@ describe('Study tests', () => {
9
11
  new Rational('(3x-2)(x-3)(x+4)', 'x^2-5x+6')
10
12
  )
11
13
 
12
- console.log(study.tex)
13
- console.log(study.asymptotes)
14
- console.log(study.derivative.fx.texFactors)
15
- console.log(study.texGrows)
14
+ // console.log(study.texSigns)
15
+ // console.log(study.asymptotes)
16
+ // console.log(study.derivative.fx.texFactors)
17
+ // console.log(study.texGrows)
18
+ //
19
+ //
20
+ // console.log('----------------')
16
21
 
22
+
23
+ let AO = study.asymptotes.filter(x => x.type === ASYMPTOTE.SLOPE)[0]
24
+
25
+ console.log(AO.tableOfSign.signs)
26
+ });
27
+
28
+ it('should create draw code block', function () {
29
+ const study = new RationalStudy(
30
+ new Rational("(3x-4)(2x+5)", "(x-4)(x+4)")
31
+ )
32
+
33
+ expect(study.drawCode()).to.be.equal("f(x)=(6*x^(2)+7*x-20)/(x^(2)-16)\n" +
34
+ "av_1=line x=-4->red,dash\n" +
35
+ "av_3=line x=4->red,dash\n" +
36
+ "ah=line y=6->orange,dash\n" +
37
+ "M_6(-20.950583847231826,5.832940216581962)*\n" +
38
+ "M_7(-0.7637018670538883,1.4170597834180383)*\n" +
39
+ "Z_8(-2.5,0)*\n" +
40
+ "Z_9(1.3333333333333333,0)*")
17
41
  });
42
+
18
43
  })