Skip to content

Commit

Permalink
Prerelease Epsilon v1.5.0
Browse files Browse the repository at this point in the history
Added:
- comp.root(comp, n)
- plot.Taylor(func, n, a, scl, rgba, domain, origin, weight, res, context)
- calc.Taylor(func, val, n, a)

Removed:
- Nothing

Changed:
- Nothing
  • Loading branch information
Zushah committed Dec 18, 2023
1 parent 798dc91 commit 0694a88
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Chalkboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,17 @@ var Chalkboard = {
conjugate: function(comp) {
return Chalkboard.comp.new(comp.a, -comp.b);
},
root: function(comp, n) {
if(Number.isInteger(n) && n > 0) {
var result = [];
var r = Chalkboard.comp.mag(comp);
var t = Chalkboard.comp.arg(comp);
for(var i = 0; i < n; i++) {
result.push(Chalkboard.comp.new(Chalkboard.real.nrt(r, n) * Chalkboard.trig.cos((t + Chalkboard.PI(2 * i)) / n), Chalkboard.real.nrt(r, n) * Chalkboard.trig.sin((t + Chalkboard.PI(2 * i)) / n)));
}
return result;
}
},
dist: function(comp_1, comp_2) {
return Chalkboard.real.sqrt(((comp_2.a - comp_1.a) * (comp_2.a - comp_1.a)) + ((comp_2.b - comp_1.b) * (comp_2.b - comp_1.b)));
},
Expand Down Expand Up @@ -1143,6 +1154,29 @@ var Chalkboard = {
context.restore();
return data;
},
Taylor: function(func, n, a, scl, rgba, domain, origin, weight, res, context) {
scl = scl || 1;
scl /= 100;
rgba = rgba || [0, 0, 0];
domain = domain || [-10, 10];
origin = origin || [canvas.width / 2, canvas.height / 2];
weight = weight || 2;
res = res || 25;
context = context || ctx;
var data = [];
context.save();
context.translate(origin[0], origin[1]);
context.lineWidth = weight;
context.strokeStyle = rgba.length === 3 ? "rgb(" + rgba[0].toString() + ", " + rgba[1].toString() + ", " + rgba[2].toString() + ")" : "rgba(" + rgba[0].toString() + ", " + rgba[1].toString() + ", " + rgba[2].toString() + ", " + rgba[3].toString() + ")";
context.beginPath();
for(var i = domain[0] / scl; i <= domain[1] / scl; i += res) {
context.lineTo(i, -Chalkboard.calc.Taylor(func, i * scl, n, a) / scl);
data.push([i, Chalkboard.calc.Taylor(func, i, n, a)]);
}
context.stroke();
context.restore();
return data;
},
Laplace: function(func, scl, rgba, domain, origin, weight, res, context) {
scl = scl || 1;
scl /= 100;
Expand Down Expand Up @@ -3411,6 +3445,19 @@ var Chalkboard = {
autocorrelation: function(func, val) {
return Chalkboard.calc.correlation(func, func, val);
},
Taylor: function(func, val, n, a) {
if(func.type === "expl") {
if(n === 0) {
return Chalkboard.real.val(func, a);
} else if(n === 1) {
return Chalkboard.real.val(func, a) + Chalkboard.calc.dfdx(func, a) * (val - a);
} else if(n === 2) {
return Chalkboard.real.val(func, a) + Chalkboard.calc.dfdx(func, a) * (val - a) + (Chalkboard.calc.d2fdx2(func, a) * (val - a) * (val - a)) / 2;
}
} else {
return "TypeError: Parameter \"func\" must be of type \"expl\".";
}
},
Laplace: function(func, val) {
if(val > 0) {
return Chalkboard.calc.fxdx(Chalkboard.real.function("(" + func.definition + ") * Math.exp(-" + val + " * x)"), 0, 10);
Expand Down
47 changes: 47 additions & 0 deletions src/ChalkboardProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,17 @@ var Chalkboard = {
conjugate: function(comp) {
return Chalkboard.comp.new(comp.a, -comp.b);
},
root: function(comp, n) {
if(Number.isInteger(n) && n > 0) {
var result = [];
var r = Chalkboard.comp.mag(comp);
var t = Chalkboard.comp.arg(comp);
for(var i = 0; i < n; i++) {
result.push(Chalkboard.comp.new(Chalkboard.real.nrt(r, n) * Chalkboard.trig.cos((t + Chalkboard.PI(2 * i)) / n), Chalkboard.real.nrt(r, n) * Chalkboard.trig.sin((t + Chalkboard.PI(2 * i)) / n)));
}
return result;
}
},
dist: function(comp_1, comp_2) {
return Chalkboard.real.sqrt(((comp_2.a - comp_1.a) * (comp_2.a - comp_1.a)) + ((comp_2.b - comp_1.b) * (comp_2.b - comp_1.b)));
},
Expand Down Expand Up @@ -1104,6 +1115,29 @@ var Chalkboard = {
popMatrix();
return data;
},
Taylor: function(func, n, a, scl, rgba, domain, origin, weight, res, context) {
scl = scl || 1;
scl /= 100;
rgba = rgba || [0, 0, 0];
domain = domain || [-10, 10];
origin = origin || [width / 2, height / 2];
weight = weight || 2;
res = res || 25;
var data = [];
pushMatrix();
translate(origin[0], origin[1]);
noFill();
strokeWeight(weight);
stroke(rgba.length === 3 ? color(rgba[0], rgba[1], rgba[2]) : color(rgba[0], rgba[1], rgba[2], rgba[3]));
beginShape();
for(var i = domain[0] / scl; i <= domain[1] / scl; i += res) {
vertex(i, -Chalkboard.calc.Taylor(func, i * scl, n, a) / scl);
data.push([i, Chalkboard.calc.Taylor(func, i, n, a)]);
}
endShape();
popMatrix();
return data;
},
Laplace: function(func, scl, rgba, domain, origin, weight, res) {
scl = scl || 1;
scl /= 100;
Expand Down Expand Up @@ -3368,6 +3402,19 @@ var Chalkboard = {
autocorrelation: function(func, val) {
return Chalkboard.calc.correlation(func, func, val);
},
Taylor: function(func, val, n, a) {
if(func.type === "expl") {
if(n === 0) {
return Chalkboard.real.val(func, a);
} else if(n === 1) {
return Chalkboard.real.val(func, a) + Chalkboard.calc.dfdx(func, a) * (val - a);
} else if(n === 2) {
return Chalkboard.real.val(func, a) + Chalkboard.calc.dfdx(func, a) * (val - a) + (Chalkboard.calc.d2fdx2(func, a) * (val - a) * (val - a)) / 2;
}
} else {
return "TypeError: Parameter \"func\" must be of type \"expl\".";
}
},
Laplace: function(func, val) {
if(val > 0) {
return Chalkboard.calc.fxdx(Chalkboard.real.function("(" + func.definition + ") * Math.exp(-" + val + " * x)"), 0, 10);
Expand Down

0 comments on commit 0694a88

Please sign in to comment.