@designliquido/delegua 0.0.1 → 0.0.2

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.
Files changed (43) hide show
  1. package/.github/CONTRIBUTING.md +0 -0
  2. package/.github/workflows/principal.yml +20 -0
  3. package/.release-it.json +8 -0
  4. package/.vscode/launch.json +2 -2
  5. package/README.md +5 -6
  6. package/bin/delegua +1 -1
  7. package/bin/delegua.cmd +1 -0
  8. package/indice.js +14 -0
  9. package/package.json +46 -37
  10. package/src/ambiente.js +53 -0
  11. package/src/{egua.js → delegua.js} +20 -20
  12. package/src/erro.js +18 -0
  13. package/src/estruturas/callable.js +5 -0
  14. package/src/estruturas/classe.js +43 -0
  15. package/src/estruturas/funcao.js +62 -0
  16. package/src/estruturas/funcaoPadrao.js +18 -0
  17. package/src/estruturas/instancia.js +27 -0
  18. package/src/estruturas/modulo.js +9 -0
  19. package/src/expr.js +52 -52
  20. package/src/interpretador.js +802 -0
  21. package/src/lexer.js +90 -89
  22. package/src/lib/globalLib.js +63 -63
  23. package/src/lib/importStdlib.js +18 -27
  24. package/src/parser.js +219 -223
  25. package/src/resolver.js +93 -93
  26. package/src/stmt.js +34 -34
  27. package/src/{tokenTypes.js → tiposDeSimbolos.js} +21 -21
  28. package/src/web.js +41 -41
  29. package/testes/testes.egua +363 -364
  30. package/index.html +0 -43
  31. package/index.js +0 -14
  32. package/src/environment.js +0 -53
  33. package/src/errors.js +0 -17
  34. package/src/interpreter.js +0 -798
  35. package/src/lib/__tests__/eguamat.test.js +0 -101
  36. package/src/lib/eguamat.js +0 -725
  37. package/src/lib/tempo.js +0 -50
  38. package/src/structures/callable.js +0 -5
  39. package/src/structures/class.js +0 -43
  40. package/src/structures/function.js +0 -62
  41. package/src/structures/instance.js +0 -27
  42. package/src/structures/module.js +0 -9
  43. package/src/structures/standardFn.js +0 -18
@@ -1,725 +0,0 @@
1
- const RuntimeError = require("../errors.js").RuntimeError;
2
-
3
- module.exports.graus = function (angle) {
4
- if (isNaN(angle) || angle === null)
5
- throw new RuntimeError(
6
- this.token,
7
- "Você deve prover um número para mat.graus(ângulo)."
8
- );
9
-
10
- return angle * (180 / Math.PI);
11
- };
12
-
13
- //Mediana de uma matriz
14
- module.exports.mediana = function (a) {
15
- if (isNaN(a) || a === null)
16
- throw new RuntimeError(
17
- this.token,
18
- "Você deve prover valores para mediana(a)."
19
- );
20
-
21
- a.sort(function (a, b) { return a - b; });
22
- const mid = a.length / 2;
23
- return mid % 1 ? a[mid - 0.5] : (a[mid - 1] + a[mid]) / 2;
24
- };
25
-
26
- /**
27
- * Calcula a moda de um vetor. A moda é o valor, ou valores, que mais são
28
- * presentes em um conjunto.
29
- * @param {inteiro[]} vetor O conjunto a ser avaliado.
30
- * @returns O novo conjunto com os valores da moda.
31
- * @see https://pt.wikipedia.org/wiki/Moda_(estat%C3%ADstica)
32
- */
33
- module.exports.moda = function (vetor) {
34
- if (!Array.isArray(vetor))
35
- throw new RuntimeError(
36
- this.token,
37
- "Parâmetro `vetor` deve ser um vetor, em min(vetor)."
38
- );
39
-
40
- if (vetor.some(isNaN))
41
- throw new RuntimeError(
42
- this.token,
43
- "Todos os elementos de `vetor` deve ser numéricos, em min(vetor)."
44
- );
45
-
46
- const objectArr = vetor.reduce(
47
- function (acc, curr) {
48
- return acc[curr] ? ++acc[curr] : acc[curr] = 1, acc
49
- },
50
- {}
51
- )
52
- const counter = []
53
- Object.keys(objectArr).filter(function (pos) {
54
- counter.push(objectArr[pos])
55
- })
56
- const max = Math.max.apply(null, counter)
57
-
58
- if (max === 1) {
59
- return []
60
- }
61
-
62
- return Object.keys(objectArr).filter(function (pos) {
63
- return objectArr[pos] === max
64
- ? objectArr[pos]
65
- : null
66
- }).map(item => Number(item))
67
- }
68
- /**
69
- * Função que sempre returna `nulo`.
70
- * Útil para comparações entre outras funções que também retornam nulo.
71
- * @returns `null` do JavaScript.
72
- */
73
- module.exports.nula = function () {
74
- return null;
75
- };
76
-
77
- /**
78
- * Constante pi.
79
- * @see https://pt.wikipedia.org/wiki/Pi
80
- */
81
- module.exports.pi = Math.PI;
82
-
83
- /**
84
- * Calcula o valor radiano de um ângulo. O radiano é o comprimento do arco formado
85
- * por um ângulo em uma circunferência.
86
- * @param {inteiro} angulo O ângulo, em graus, do valor radiano desejado.
87
- * @returns O valor, em radianos, do arco formado pelo ângulo.
88
- * @see https://pt.wikipedia.org/wiki/Radiano
89
- */
90
- module.exports.radiano = function (angulo) {
91
- if (!Number.isInteger(angulo))
92
- throw new RuntimeError(
93
- this.token,
94
- "Você deve prover um número inteiro para o parâmetro `angulo`, em radiano(angulo)."
95
- );
96
-
97
- return angulo * (Math.PI / 180);
98
- };
99
-
100
- //FUNÇÃO AFIM E QUADRÁTICA
101
- /**
102
- * Gera valores para abscissa.
103
- * @param {inteiro} distancia A distância entra dois pontos.
104
- * @param {inteiro} valorPontoCentral O ponto central na abscissa.
105
- * @param {inteiro} numeroPontos Número de pontos a serem gerados (padrão: 7).
106
- * @returns Um vetor, contendo o número de pontos informado ou definido por padrão em uma abscissa.
107
- * Se o número informado é par, um ponto negativo a mais é gerado.
108
- */
109
- module.exports.gerarPontosAbscissa = function (distancia, valorPontoCentral, numeroPontos) {
110
- if (!Number.isInteger(distancia))
111
- throw new RuntimeError(
112
- this.token,
113
- "Você deve prover um valor inteiro para o parâmetro `distancia`, em gerarPontosAbscissa(distancia, valorInicial)."
114
- );
115
-
116
- if (!Number.isInteger(valorPontoCentral))
117
- throw new RuntimeError(
118
- this.token,
119
- "Você deve prover um valor inteiro para o parâmetro `valorInicial`, em gerarPontosAbscissa(distancia, valorInicial)."
120
- );
121
-
122
- if (!numeroPontos) {
123
- numeroPontos = 7;
124
- }
125
-
126
- const elementoInicial = valorPontoCentral - (((numeroPontos / 2) >> 0) * distancia);
127
- const x = [];
128
- for (let i = 0; i < numeroPontos; i++) {
129
- x.push(elementoInicial + (i * distancia));
130
- }
131
-
132
- return x;
133
- };
134
-
135
- //Raíz da Função Afim
136
- module.exports.fun1R = function (a, b) {
137
- if (isNaN(a) || a === null || isNaN(b) || b === null)
138
- throw new RuntimeError(
139
- this.token,
140
- "Você deve prover valores para fun1R(valor1,valor2)."
141
- );
142
- return (-1 * b) / a;
143
- };
144
-
145
- //Intervalo Preenchido
146
- module.exports.linspace = function (startValue, stopValue, cardinality) {
147
- if (
148
- isNaN(startValue) || startValue === null ||
149
- isNaN(stopValue) || stopValue === null ||
150
- isNaN(cardinality) || cardinality === null
151
- )
152
- throw new RuntimeError(
153
- this.token,
154
- "Você deve prover valores para linspace(valor1,valor2,valor3)."
155
- );
156
- const lista = [];
157
- const step = (stopValue - startValue) / (cardinality - 1);
158
- for (var i = 0; i < cardinality; i++) {
159
- arr.push(startValue + (step * i));
160
- }
161
- return lista;
162
- };
163
-
164
- //Raízes da Função Quadrática
165
- module.exports.fun2R = function (a, b, c) {
166
- if (isNaN(a) || a === null)
167
- throw new RuntimeError(
168
- this.token,
169
- "Você deve prover valores para fun2R(a,b,c)."
170
- );
171
-
172
- const r1 = (-1 * b + Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a);
173
- const r2 = (-1 * b - Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a);
174
-
175
- const xv = (-1 * b) / (2 * a);
176
- const yv = (-1 * (Math.pow(b, 2) - (4 * a * c))) / 4 * a;
177
-
178
- return [xv, yv];
179
- };
180
-
181
- //Aproximação de valores
182
- module.exports.aprox = function (x, z) {
183
- if (isNaN(x) || x === null || isNaN(z) || z === null)
184
- throw new RuntimeError(
185
- this.token,
186
- "Você deve prover valores para aprox(x,z)."
187
- );
188
- if (z == undefined) { z = 2; }
189
- if (typeof (x) == "number") { x = x.toFixed(z) }
190
- else if (x[0].length == undefined) { // 1D array
191
- for (let i = 0; i < x.length; i++) {
192
- x[i] = parseFloat(x[i].toFixed(z));
193
- }
194
- } else
195
- for (let i = 0; i < x.length; i++) { // 2D array
196
- for (let j = 0; j < x[0].length; j++) {
197
- x[i][j] = parseFloat(x[i][j].toFixed(z));
198
- }
199
- }
200
- return x;
201
- };
202
-
203
- //Parâmetros da Função
204
- module.exports.matrizn = function (z) {
205
- if (isNaN(z) || z === null)
206
- throw new RuntimeError(
207
- this.token,
208
- "Você deve prover valores para matrizn(z)."
209
- );
210
- const n = arguments.length;
211
- const data = Array.from(Array(1), () => new Array(n));
212
- for (let i = 0; i < n; i++) { data[0][i] = arguments[i]; }
213
- return matriz(data);
214
- };
215
-
216
- //Vetor de pontos aleatórios
217
- module.exports.pontosAleatorios = function (n) {
218
- if (isNaN(n) || n === null)
219
- throw new RuntimeError(
220
- this.token,
221
- "Você deve prover valores para pale(n)."
222
- );
223
- if (ex == undefined) { ex = 0; }
224
- const x = [];
225
- x[0] = 100;
226
- for (let i = 1; i < n; i++) {
227
- x[i] = ex + x[i - 1] + Math.random() * 2 - 1;
228
- }
229
- const xx = aprox(x, 2);
230
- return xx;
231
- };
232
-
233
- //Intervalo A-B
234
- module.exports.vet = function (a, b) {
235
- if (isNaN(a) || a === null || isNaN(b) || b === null)
236
- throw new RuntimeError(
237
- this.token,
238
- "Você deve prover valores para vet(a,b)."
239
- );
240
- const data = Array.from(Array(1), () => new Array(b - a + 1));
241
-
242
- for (let i = 0; i < data[0].length; i++) {
243
- data[0][i] = a + i;
244
- }
245
- return matrizn(data);
246
- };
247
-
248
-
249
- /**
250
- * Conta quantas vezes um determinado valor aparece em um vetor.
251
- * @param {qualquer[]} vetor Vetor de elementos
252
- * @param {qualquer} valor Valor a ser encontrado no vetor
253
- * @returns Valor inteiro, com o número de vezes que `valor` foi encontrado em `vetor`.
254
- */
255
- module.exports.numeroOcorrencias = function (vetor, valor) {
256
- if (!Array.isArray(vetor))
257
- throw new RuntimeError(
258
- this.token,
259
- "Parâmetro `vetor` deve ser um vetor, em numeroOcorrencias(vetor, valor)."
260
- );
261
-
262
- return vetor.filter((v) => (v === valor)).length;
263
- };
264
-
265
- /* ESTATÍSTICA */
266
-
267
- /**
268
- * Encontra o elemento máximo em um vetor.
269
- * @param {inteiro[]} vetor Um vetor de números inteiros.
270
- * @returns O maior número encontrado em um vetor.
271
- */
272
- module.exports.max = function (vetor) {
273
- if (!Array.isArray(vetor))
274
- throw new RuntimeError(
275
- this.token,
276
- "Parâmetro `vetor` deve ser um vetor, em max(vetor)."
277
- );
278
-
279
- if (vetor.some(isNaN))
280
- throw new RuntimeError(
281
- this.token,
282
- "Todos os elementos de `vetor` deve ser numéricos, em max(vetor)."
283
- );
284
-
285
- return Math.max.apply(null, vetor);
286
- };
287
-
288
- /**
289
- * Encontra o elemento mínimo em um vetor.
290
- * @param {inteiro[]} vetor Um vetor de números inteiros.
291
- * @returns O menor número encontrado em um vetor.
292
- */
293
- module.exports.min = function (vetor) {
294
- if (!Array.isArray(vetor))
295
- throw new RuntimeError(
296
- this.token,
297
- "Parâmetro `vetor` deve ser um vetor, em min(vetor)."
298
- );
299
-
300
- if (vetor.some(isNaN))
301
- throw new RuntimeError(
302
- this.token,
303
- "Todos os elementos de `vetor` deve ser numéricos, em min(vetor)."
304
- );
305
-
306
- return Math.min.apply(null, vetor);
307
- };
308
-
309
- //Soma de determinada matriz
310
- module.exports.smtr = function (a) {
311
- if (isNaN(a) || a === null)
312
- throw new RuntimeError(
313
- this.token,
314
- "Você deve prover valores para smtr(a)."
315
- );
316
-
317
- let z = 0;
318
- if (a.length == 1) { // a is a 1D row array
319
- for (let j = 0; j < a[0].length; j++) { z = z + a[0][j]; }
320
- }
321
- else if (a[0].length == 1) { // a is a 1D column array
322
- for (let i = 0; i < a.length; i++) { z = z + a[i][0]; }
323
- }
324
- else {
325
- for (let j = 0; j < a.length; j++) { z = z + a[j]; }
326
- }
327
-
328
- return aprox(z, 2);
329
- };
330
-
331
- // Retorna a média de um vetor de números
332
- module.exports.media = function () {
333
- const argumentsLength = Object.keys(arguments).length;
334
-
335
- if (argumentsLength <= 0) {
336
- throw new RuntimeError(
337
- this.token,
338
- "Você deve fornecer um parâmetro para a função."
339
- );
340
- }
341
-
342
- if (argumentsLength > 1) {
343
- throw new RuntimeError(
344
- this.token,
345
- "A função recebe apenas um parâmetro."
346
- );
347
- }
348
-
349
- // Pega o primeiro argumento do objeto de argumentos
350
- const args = arguments['0'];
351
-
352
- if (!Array.isArray(args)) {
353
- throw new RuntimeError(
354
- this.token,
355
- "Você deve fornecer um parâmetro do tipo vetor."
356
- );
357
- }
358
-
359
- // Valida se o array está vazio.
360
- if (!args.length) {
361
- throw new RuntimeError(
362
- this.token,
363
- "Vetor vazio. Você deve fornecer ao menos um valor ao vetor."
364
- );
365
- }
366
-
367
- // Valida se o array contém apenas valores do tipo número.
368
- args.forEach(item => {
369
- if (typeof item !== 'number') {
370
- throw new RuntimeError(
371
- this.token,
372
- "Você deve fornecer um vetor contendo apenas valores do tipo número."
373
- );
374
- }
375
- })
376
-
377
- // Soma todos os itens.
378
- const valoresSomados = args.reduce(
379
- (acumulador, itemAtual) => acumulador + itemAtual, 0);
380
-
381
- // Faz o cáculo da média em si e retorna.
382
- return (valoresSomados / args.length);
383
- };
384
-
385
- //Média aritmética de uma matriz
386
- module.exports.ve = function (a) {
387
- if (isNaN(a) || a === null)
388
- throw new RuntimeError(
389
- this.token,
390
- "Você deve prover valores para ve(a)."
391
- );
392
-
393
- if (a.length == 1) { return aprox(smtr(a) / a[0].length, 4); } // a is a row array
394
- if (a[0].length == 1) { return aprox(smtr(a) / a.length, 4); } // a is a column array
395
- if (a[0].length == undefined) { return aprox(smtr(a) / a.length, 4); }
396
- };
397
-
398
- //Soma dos quadrados dos resíduos (sqr) de uma matriz
399
- module.exports.sqr = function (a) {
400
- if (isNaN(a) || a === null)
401
- throw new RuntimeError(
402
- this.token,
403
- "Você deve prover valores para sqr(a)."
404
- );
405
-
406
- const mean = ve(array);
407
- let sum = 0;
408
- let i = array.length;
409
- let tmp;
410
- while (--i >= 0) {
411
- tmp = array[i] - mean;
412
- sum += tmp * tmp;
413
- }
414
- return sum;
415
- };
416
-
417
- //Variação de uma matriz
418
- module.exports.variancia = function (array, flag) {
419
- if (isNaN(array) || array === null || isNaN(flag) || flag === null)
420
- throw new RuntimeError(
421
- this.token,
422
- "Você deve prover valores para variancia(matriz, flag)."
423
- );
424
-
425
- if (flag == undefined) { flag = 1; }
426
- return sqr(array) / (array.length - (flag ? 1 : 0));
427
- };
428
-
429
- //Covariância de duas matrizes
430
- module.exports.covar = function (array1, array2) {
431
- if (isNaN(array1) || array1 === null || isNaN(array1) || array2 === null)
432
- throw new RuntimeError(
433
- this.token,
434
- "Você deve prover valores para covar(matriz1, matriz2)."
435
- );
436
-
437
- var u = ve(array1);
438
- var v = ve(array2);
439
- var arr1Len = array1.length;
440
- var sq_dev = new Array(arr1Len);
441
- for (var i = 0; i < arr1Len; i++)
442
- sq_dev[i] = (array1[i] - u) * (array2[i] - v);
443
- return smtr(sq_dev) / (arr1Len - 1);
444
- };
445
-
446
- /*TRIGONOMETRIA*/
447
- //Seno de um número
448
- module.exports.sen = function (x) {
449
- if (isNaN(x) || x === null)
450
- throw new RuntimeError(
451
- this.token,
452
- "Você deve prover valores para sen(x)."
453
- );
454
-
455
- return Math.sin(x);
456
- };
457
-
458
- //Cosseno de um número
459
- module.exports.cos = function (x) {
460
- if (isNaN(x) || x === null)
461
- throw new RuntimeError(
462
- this.token,
463
- "Você deve prover valores para cos(x)."
464
- );
465
-
466
- return Math.cos(x);
467
- };
468
-
469
- //Tangente de um número
470
- module.exports.tan = function (x) {
471
- if (isNaN(x) || x === null)
472
- throw new RuntimeError(
473
- this.token,
474
- "Você deve prover valores para tan(x)."
475
- );
476
-
477
- return Math.tan(x);
478
- };
479
-
480
- //Arco cosseno de um número
481
- module.exports.arcos = function (x) {
482
- if (isNaN(x) || x === null)
483
- throw new RuntimeError(
484
- this.token,
485
- "Você deve prover valores para arcos(x)."
486
- );
487
-
488
- return Math.acos(x);
489
- };
490
-
491
- //Arco seno de um número
492
- module.exports.arsen = function (x) {
493
- if (isNaN(x) || x === null)
494
- throw new RuntimeError(
495
- this.token,
496
- "Você deve prover valores para arsen(x)."
497
- );
498
-
499
- return Math.asin(x);
500
- };
501
-
502
- //Arco tangente de um número
503
- module.exports.artan = function (x) {
504
- if (isNaN(x) || x === null)
505
- throw new RuntimeError(
506
- this.token,
507
- "Você deve prover valores para artan(x)."
508
- );
509
-
510
- return Math.atan(x)
511
- };
512
-
513
- //Exponencial
514
- module.exports.exp = function (x) {
515
- if (isNaN(x) || x === null)
516
- throw new RuntimeError(
517
- this.token,
518
- "Você deve prover valores para exp(x)."
519
- );
520
-
521
- return Math.exp(x);
522
- };
523
-
524
- //Logaritmo natural
525
- module.exports.log = function (x) {
526
- if (isNaN(x) || x === null)
527
- throw new RuntimeError(
528
- this.token,
529
- "Você deve prover valores para log(x)."
530
- );
531
-
532
- return Math.log(x);
533
- };
534
-
535
- // Retorna a base elevada ao expoente
536
- module.exports.potencia = function (base, expoente) {
537
- if (typeof base !== 'number' || typeof expoente !== 'number') {
538
- throw new RuntimeError(
539
- this.token,
540
- "Os parâmetros devem ser do tipo número."
541
- );
542
- }
543
-
544
- return Math.pow(base, expoente);
545
- };
546
-
547
- //Raíz quadrada
548
- module.exports.raizq = function (x) {
549
- if (isNaN(x) || x === null)
550
- throw new RuntimeError(
551
- this.token,
552
- "Você deve prover valores para raizq(x)."
553
- );
554
-
555
- return Math.sqrt(x);
556
- };
557
-
558
- /*CINEMÁTICA*/
559
-
560
- //Velocidade média
561
- module.exports.velocidadeMedia = function (s, t) {
562
- if (isNaN(s) || s === null || isNaN(t) || t === null)
563
- throw new RuntimeError(
564
- this.token,
565
- "Você deve prover valores para velocidadeMedia(d,t)."
566
- );
567
-
568
- return (s / t);
569
- };
570
-
571
- //Espaço percorrido
572
- module.exports.deltaS = function (s0, s) {
573
- if (isNaN(s0) || s0 === null || isNaN(s) || s === null)
574
- throw new RuntimeError(
575
- this.token,
576
- "Você deve prover valores para deltas(e0,e1)."
577
- );
578
- ds = s - s0;
579
- return ds;
580
- };
581
-
582
- //Tempo Percorrido
583
- module.exports.deltaT = function (t0, t) {
584
- if (isNaN(t0) || t0 === null || isNaN(t) || t === null)
585
- throw new RuntimeError(
586
- this.token,
587
- "Você deve prover valores para deltat(t0,t1)."
588
- );
589
- dt = t - t;
590
- return dt;
591
- };
592
-
593
- // Cálculo de aceleração
594
- module.exports.aceleracao = function (
595
- velocidadeFinal, velocidadeInicial, tempoFinal, tempoInicial) {
596
-
597
- if (
598
- velocidadeFinal === null ||
599
- velocidadeInicial === null ||
600
- tempoFinal === null ||
601
- tempoInicial === null
602
- ) {
603
- throw new RuntimeError(
604
- this.token,
605
- "Devem ser fornecidos quatro parâmetros obrigatórios."
606
- );
607
- }
608
-
609
- if (
610
- typeof velocidadeFinal !== 'number' ||
611
- typeof velocidadeInicial !== 'number' ||
612
- typeof tempoFinal !== 'number' ||
613
- typeof tempoInicial !== 'number'
614
- ) {
615
- throw new RuntimeError(
616
- this.token,
617
- "Todos os parâmetros devem ser do tipo número."
618
- );
619
- }
620
-
621
- return (velocidadeFinal - velocidadeInicial) / (tempoFinal - tempoInicial);
622
- };
623
-
624
- //Função Horária da Posição (M.R.U)
625
- module.exports.mrufh = function (s0, v, t) {
626
- if (isNaN(s0) || s0 === null)
627
- throw new RuntimeError(
628
- this.token,
629
- "Você deve prover valores para mrufh(s0,v,t)."
630
- );
631
- t = t + 1;
632
- const s = new Array();
633
- let index = 0;
634
- for (var i = 0; i < t; i++) {
635
- s[index] = s0 + v * i;
636
- index++;
637
- }
638
-
639
- return ["Função: " + s0 + "+(" + v + ")*t" + "<br>" + "Posições: " + s];
640
- };
641
-
642
- //Gráfico da velocidade (M.R.U.V)
643
- module.exports.mruv = function (s0, s, a) {
644
- if (
645
- isNaN(s0) || s0 === null ||
646
- isNaN(s) || s === null ||
647
- isNaN(a) || a === null
648
- )
649
- throw new RuntimeError(
650
- this.token,
651
- "Você deve prover valores para mruv(Pi, Vf, A)."
652
- );
653
- const vf = new Array();
654
- const x = new Array();
655
- let v = new Array();
656
- let index = 0;
657
- for (var i = 0; i < s; i++) {
658
- v = index;
659
- vf[index] = Math.sqrt(2 * a * (index - s0));
660
- x[index] = i;
661
- index++;
662
- }
663
-
664
- return vf;
665
- };
666
-
667
- /*Controle e Servomecanismos*/
668
- module.exports.pid = function (Mo, t, K, T1, T2) {
669
- if (
670
- isNaN(Mo) || Mo === null ||
671
- isNaN(t) || t === null ||
672
- isNaN(K) || K === null ||
673
- isNaN(T1) || T1 === null ||
674
- isNaN(T2) || T2 === null
675
- ) {
676
- throw new RuntimeError(
677
- this.token,
678
- "Você deve prover valores para pid(Ov, Ts, K, T1, T2)."
679
- );
680
- }
681
- pi = Math.PI;//Pi da bilbioteca Math.js
682
-
683
- //Amortecimento Relativo
684
- csi = (-1 * (Math.log((Mo / 100)))) / (Math.sqrt(Math.pow(pi, 2) + (pot((Math.log((Mo / 100))), 2))));
685
-
686
- //Frequência Natural
687
- Wn = (4) / (t * csi);
688
-
689
- //Controlador Proporcional (P)
690
- Kp = 20 * (Math.pow(csi, 2) * Math.pow(Wn, 2) * T1 * T2) + ((Math.pow(Wn, 2) * T1 * T2) - 1) / (K);
691
-
692
- //Controlador Integral (I)
693
- Ki = (10 * csi * (Math.pow(Wn, 3)) * T1 * T2) / (K);
694
-
695
- //Controlador Derivativo (D)
696
- Kd = (12 * csi * Wn * T1 * T2 - T1 - T2) / (K);
697
-
698
- return [csi, Wn, Kp, Ki, Kd];
699
- };
700
-
701
- // Retorna o comprimento de um vetor
702
- module.exports.comp = function (array) {
703
-
704
- if (!Array.isArray(array)) {
705
- throw new RuntimeError(
706
- this.token,
707
- "O valor passado pra função deve ser um vetor."
708
- );
709
- }
710
-
711
- return array.length;
712
- };
713
-
714
- // Retorna o menor número inteiro dentre o valor de "value"
715
- module.exports.minaprox = function (value) {
716
-
717
- if (typeof value !== 'number') {
718
- throw new RuntimeError(
719
- this.token,
720
- "O valor passado pra função deve ser um número."
721
- );
722
- }
723
-
724
- return Math.floor(value);
725
- };