JSFiddle - React, Tailwind, and code Playground

by evgkch

JavaScript

class P {
	static d(p){
  	const np = new Float32Array(p.powers.length - 1);
    for (let i = 0; i < np.length; i++)
    {
    	np[i] = p.powers[i + 1] * (i + 1)
    };
    return new P(np);
  }
  add(p1, p2){
  	const np = new Float32Array(Math.map(p1.powers.length, p2.powers.length));
    
  }
	constructor(powers){
  	this.powers = new Float32Array(powers);
  }
  calc(x){
  	return this.powers.reduce((a, b, i) => a + b * Math.pow(x, i));
  }
}

const p = new P([1, 1, 0, 1]);

console.log(p.calc(0))
console.log(p.calc(-2))
console.log(p.calc(2))

const np = P.d(p);

console.log(np)

console.time();
const res = new Float32Array(1000);
for (let i = 0; i < 1000; i++)
{
	res[i] = p.calc(i * 0.1);
}
console.timeEnd();
console.log(res);

function B(n, k)

// x^2 + y^2 - 1 = 0
// x dx + y dy = 0
// dy / dx = - x / y
// dx ** 2 + x ddx + dy ** 2 + y ddy = 0
// 1 + y' ** 2 + y y'' = 0 -> y'' = (- 1 - 2 y')/y ->