Routh stability calculator algorithm in javascript
up vote
1
down vote
favorite
Im trying to write algorithm for routh stability criterion, I load inputs into array then I try to calculate other values with algorithm. But Im struggling with that algorithm
this is what I have right now:
function parse() {
var str = document.getElementById("input").value;
var n = str.split(/[-+]/).length;
console.log(n);
var x = ;
x = str.split(/[-+]/);
var a = ;
for (var i = 0; i <= n - 1; i++) {
if (x[i].charAt(0) == "s") {
a[i] = 1;
} else {
a[i] = Number(x[i].charAt(0));
}
}
i = 0;
console.log(a[0]);
console.log(a[1]);
console.log(a[2]);
console.log(a[3]);
var k = ;
k[0] = a[0] / a[1];
var b = ;
for (i; i < n - 2; i++) {
b[i] = a[i + 2] - (k[i] * a[i + 3]); // a[i+3] is undefined
k[i + 1] = a[i + 1] / b[i];
console.log(b[0]);
console.log(b[1]);
console.log(k[0]);
console.log(k[1]);
}
}
<input type="text" name="input" id="input">
<button onclick="parse()">calculate</button>
Values in blue I have and values in red I need, I dont know how to define when there is no more values in array to calculate next line.
routh criterion
javascript arrays math
add a comment |
up vote
1
down vote
favorite
Im trying to write algorithm for routh stability criterion, I load inputs into array then I try to calculate other values with algorithm. But Im struggling with that algorithm
this is what I have right now:
function parse() {
var str = document.getElementById("input").value;
var n = str.split(/[-+]/).length;
console.log(n);
var x = ;
x = str.split(/[-+]/);
var a = ;
for (var i = 0; i <= n - 1; i++) {
if (x[i].charAt(0) == "s") {
a[i] = 1;
} else {
a[i] = Number(x[i].charAt(0));
}
}
i = 0;
console.log(a[0]);
console.log(a[1]);
console.log(a[2]);
console.log(a[3]);
var k = ;
k[0] = a[0] / a[1];
var b = ;
for (i; i < n - 2; i++) {
b[i] = a[i + 2] - (k[i] * a[i + 3]); // a[i+3] is undefined
k[i + 1] = a[i + 1] / b[i];
console.log(b[0]);
console.log(b[1]);
console.log(k[0]);
console.log(k[1]);
}
}
<input type="text" name="input" id="input">
<button onclick="parse()">calculate</button>
Values in blue I have and values in red I need, I dont know how to define when there is no more values in array to calculate next line.
routh criterion
javascript arrays math
my input looks like this: s^3+4s^2+4s+8
– Thomas231
Nov 11 at 15:23
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Im trying to write algorithm for routh stability criterion, I load inputs into array then I try to calculate other values with algorithm. But Im struggling with that algorithm
this is what I have right now:
function parse() {
var str = document.getElementById("input").value;
var n = str.split(/[-+]/).length;
console.log(n);
var x = ;
x = str.split(/[-+]/);
var a = ;
for (var i = 0; i <= n - 1; i++) {
if (x[i].charAt(0) == "s") {
a[i] = 1;
} else {
a[i] = Number(x[i].charAt(0));
}
}
i = 0;
console.log(a[0]);
console.log(a[1]);
console.log(a[2]);
console.log(a[3]);
var k = ;
k[0] = a[0] / a[1];
var b = ;
for (i; i < n - 2; i++) {
b[i] = a[i + 2] - (k[i] * a[i + 3]); // a[i+3] is undefined
k[i + 1] = a[i + 1] / b[i];
console.log(b[0]);
console.log(b[1]);
console.log(k[0]);
console.log(k[1]);
}
}
<input type="text" name="input" id="input">
<button onclick="parse()">calculate</button>
Values in blue I have and values in red I need, I dont know how to define when there is no more values in array to calculate next line.
routh criterion
javascript arrays math
Im trying to write algorithm for routh stability criterion, I load inputs into array then I try to calculate other values with algorithm. But Im struggling with that algorithm
this is what I have right now:
function parse() {
var str = document.getElementById("input").value;
var n = str.split(/[-+]/).length;
console.log(n);
var x = ;
x = str.split(/[-+]/);
var a = ;
for (var i = 0; i <= n - 1; i++) {
if (x[i].charAt(0) == "s") {
a[i] = 1;
} else {
a[i] = Number(x[i].charAt(0));
}
}
i = 0;
console.log(a[0]);
console.log(a[1]);
console.log(a[2]);
console.log(a[3]);
var k = ;
k[0] = a[0] / a[1];
var b = ;
for (i; i < n - 2; i++) {
b[i] = a[i + 2] - (k[i] * a[i + 3]); // a[i+3] is undefined
k[i + 1] = a[i + 1] / b[i];
console.log(b[0]);
console.log(b[1]);
console.log(k[0]);
console.log(k[1]);
}
}
<input type="text" name="input" id="input">
<button onclick="parse()">calculate</button>
Values in blue I have and values in red I need, I dont know how to define when there is no more values in array to calculate next line.
routh criterion
function parse() {
var str = document.getElementById("input").value;
var n = str.split(/[-+]/).length;
console.log(n);
var x = ;
x = str.split(/[-+]/);
var a = ;
for (var i = 0; i <= n - 1; i++) {
if (x[i].charAt(0) == "s") {
a[i] = 1;
} else {
a[i] = Number(x[i].charAt(0));
}
}
i = 0;
console.log(a[0]);
console.log(a[1]);
console.log(a[2]);
console.log(a[3]);
var k = ;
k[0] = a[0] / a[1];
var b = ;
for (i; i < n - 2; i++) {
b[i] = a[i + 2] - (k[i] * a[i + 3]); // a[i+3] is undefined
k[i + 1] = a[i + 1] / b[i];
console.log(b[0]);
console.log(b[1]);
console.log(k[0]);
console.log(k[1]);
}
}
<input type="text" name="input" id="input">
<button onclick="parse()">calculate</button>
function parse() {
var str = document.getElementById("input").value;
var n = str.split(/[-+]/).length;
console.log(n);
var x = ;
x = str.split(/[-+]/);
var a = ;
for (var i = 0; i <= n - 1; i++) {
if (x[i].charAt(0) == "s") {
a[i] = 1;
} else {
a[i] = Number(x[i].charAt(0));
}
}
i = 0;
console.log(a[0]);
console.log(a[1]);
console.log(a[2]);
console.log(a[3]);
var k = ;
k[0] = a[0] / a[1];
var b = ;
for (i; i < n - 2; i++) {
b[i] = a[i + 2] - (k[i] * a[i + 3]); // a[i+3] is undefined
k[i + 1] = a[i + 1] / b[i];
console.log(b[0]);
console.log(b[1]);
console.log(k[0]);
console.log(k[1]);
}
}
<input type="text" name="input" id="input">
<button onclick="parse()">calculate</button>
javascript arrays math
javascript arrays math
edited Nov 11 at 15:22
Ele
22.6k42044
22.6k42044
asked Nov 11 at 15:21
Thomas231
63
63
my input looks like this: s^3+4s^2+4s+8
– Thomas231
Nov 11 at 15:23
add a comment |
my input looks like this: s^3+4s^2+4s+8
– Thomas231
Nov 11 at 15:23
my input looks like this: s^3+4s^2+4s+8
– Thomas231
Nov 11 at 15:23
my input looks like this: s^3+4s^2+4s+8
– Thomas231
Nov 11 at 15:23
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250155%2frouth-stability-calculator-algorithm-in-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
my input looks like this: s^3+4s^2+4s+8
– Thomas231
Nov 11 at 15:23