Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show equation being plotted #2

Open
wants to merge 3 commits into
base: customization
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _posts/2017-12-15-polynomial-roots-toy.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Grab the red dots and play around! Or jump to the
<input type="number" name="degView" id="degView" class="myDegInput" min="1" max="7" step="1" value="4">
</form>

<label for="equationTextBox" class="myLabel">Equation (generated from degree):</label>
<input type="text" id="equationTextBox" width="30" disabled>

<!------------------------------------------------------------>
<!-- CODE -->

Expand Down
15 changes: 15 additions & 0 deletions assets/js/poly-root-toy.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@
'showingDiscRoots': false,
'discRootPoints': [],

'updateEquation': function() {
var formula_pieces = [];
// Degree zero is just the coefficient.
formula_pieces.push("a0");
// Lower degrees have a coefficient ai and x^i.
for (var i = 1; i < this.degree; i++) {
formula_pieces.push("a" + i + " x^" + i);
}
// The higest-degree term has a coefficient of 1.
formula_pieces.push("x^" + this.degree);
document.getElementById('equationTextBox').value =
formula_pieces.join(" + ") + " = 0";
},

'updatePolyCoeffsFromRoots': function() {
this.degree = this.roots.length;
this.p = Polynomial.fromRoots(this.roots);
Expand Down Expand Up @@ -327,6 +341,7 @@

controller.updateRootView();
controller.updateCoeffView();
controller.updateEquation();
};
})(this);
},
Expand Down