劳斯稳定方法-RouthMethod
今天上<线性控制系统工程>课时, 讲到系统稳定性的一种判定方法: Routh's Method
见今晚没别的事做, 就用来练习了一下JavaScript.
具体算法请见:
Module.9. Routh method,root locus_magnitude and phase equations.rar
测试网址:
Routh Method
JavaScript源代码:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Routh's Method</title>
<style type="text/css">
table td {
border: 1px solid;
padding: 5px;
}
</style>
<script type="text/javascript" language="javascript">
//跨浏览器的event辅助工具
var EventUtil = new Object;
//添加事件监听者
EventUtil.addEventHandler = function (oTarget, sEventType, fnHandler) {
if(oTarget.addEventListener) {
oTarget.addEventListener(sEventType, fnHandler, false);
}
else if (oTarget.attachEvent) {
oTarget.attachEvent("on" + sEventType, fnHandler);
}
else {
oTarget["on" + sEventType] = fnHandler;
}
}
var RouthArray = function(params) {
this._params = params;
this._count = this._params.length;
this._datas = [];
this._onImaginaryAxis = 0;
var index = 0;
for(var row = 0; row < 2; row++) {
this._datas[row] = [];
var count = Math.ceil(this._count/2);
for(var col = 0; col<count; col++) {
this._datas[row][col] = {};
this._datas[row][col].value = (this._params[index]!=null)?window.parseFloat(this._params[index]) : 0;
index += 2;
}
index = 1;
}
for(var row = 2; row < this._count; row++) {
this._datas[row] = [];
var zeroCount = 0;
for(var col = 0; this._datas[row-2][col+1]!=null && this._datas[row-2][col+1].value!=0; col++) {
if(this._datas[row-1][col+1]==null) {
this._datas[row-1][col+1] = {};
this._datas[row-1][col+1].value = 0;
}
this._datas[row][col] = {};
this._datas[row][col].value = (this._datas[row-1][0].value*this._datas[row-2][col+1].value
- this._datas[row-2][0].value*this._datas[row-1][col+1].value) / this._datas[row-1][0].value;
if(this._datas[row][col].value == 0) {
zeroCount++;
this._datas[row][col].isZero = true;
}
}
if(zeroCount == (Math.floor((this._count-row-1)/2)+1)) { //全为0
this._onImaginaryAxis++; //增加一对纯虚根, 即在虚轴上
var n = this._count-row;
var ct = Math.floor(n/2);
var r = row-1;
for(var c = 0; c<ct; c++) {
this._datas[row][c].value = this._datas[r][c].value*(n-2*c); //求导
}
}
else if(this._datas[row][0].value == 0 && (this._datas[row][1] != null && this._datas[row][1].value != 0)) { //第一列为0
this._datas[row][0].value = 0.00000001;
}
}
this.show();
}
RouthArray.prototype = {
show: function() {
var belowZero = this._datas[0][0].value > 0;
var signCngCount = 0;
var container = document.getElementById("container");
if(container) {
container.innerHTML = "";
}
else {
container = document.createElement("div");
container.id = "container";
document.body.appendChild(container);
}
var table = document.createElement("table");
container.appendChild(table);
for(var row=0; row<this._count; row++) {
// var tr = document.createElement("tr"); //IE不支持此方式
// table.appendChild(tr);
var tr = table.insertRow(-1);
var td = document.createElement("td");
td.innerHTML = "s"+(this._count-row-1)+":";
tr.appendChild(td);
for(var col=0; col<this._datas[row].length; col++) {
var td = document.createElement("td");
td.innerHTML = this._datas[row][col].value + (this._datas[row][col].isZero? "(0)" : "");
tr.appendChild(td);
}
if(belowZero) {
if(this._datas[row][0].value < 0) {
belowZero =!belowZero;
signCngCount++;
}
}
else {
if(this._datas[row][0].value > 0) {
belowZero =!belowZero;
signCngCount++;
}
}
}
var p = document.createElement("p");
if(this._onImaginaryAxis!=0) {
p.innerHTML = "虽然首列符号没有变化, 但在虚轴有<b><font color='red'>"+this._onImaginaryAxis
+"</font></b>对关于原点对称的根, 所以系统是<b><font color='red'>不稳定的</font></b>.";
}
else if(signCngCount == 0) {
p.innerHTML = "Since there are no sign changes in the first column, there are no closed-loop poles to the"+
" right of the imaginary axis, and the System is <b><font color='red'>stable</font></b>.<br />";
p.innerHTML += "由于首列符号没有变化, 则虚轴的右侧没有闭环极点, 所以系统是<b><font color='red'>稳定的</font></b>.";
}
else {
p.innerHTML = "Since there are <b><font color='red'>"+signCngCount
+"</font></b> sign changes in the first column, there are <b><font color='red'>"
+signCngCount+"</font></b> closed-loop poles to the"+
" right of the imaginary axis, and the System is <b><font color='red'>not stable</font></b>.<br />";
p.innerHTML += "由于首列符号变化了<b><font color='red'>"+signCngCount
+"</font></b>次, 则虚轴的右侧有<b><font color='red'>"+signCngCount
+"</font></b>对闭环极点, 所以系统是<b><font color='red'>不稳定的</font></b>.";
}
container.appendChild(p);
}
}
EventUtil.addEventHandler(window,"load", function() {
EventUtil.addEventHandler(document.getElementById("btnSubmit"),"click", function() {
new RouthArray(document.getElementById("inputParams").value.split(","));
});
});
</script>
</head>
<body>
<p>Test values: <br />
(1)s^4 + 2*s^3 + 3*s^2 + 2*s + 12 = 0 :
<br /><b><font color='red'>1,2,3,2,12</font></b><br />
(1)s^6 + 4*s^5 + 8*s^4 + 10*s^3 + 8*s^2 + 4*s + 1 = 0 :
<br /><b><font color='red'>1,4,8,10,8,4,1</font></b><br />
(3)s^4 + 3*s^3 + 4*s^2 + 12*s + 16 = 0 :
<br /><b><font color='red'>1,3,4,12,16</font></b><br />
(4)s^5 + s^4 + 2*s^3 + 2*s^2 + 3*s + 5 = 0 :
<br /><b><font color='red'>1,1,2,2,3,5</font></b><br />
(5)s^5 + 3*s^4 + 3*s^3 + 9*s^2 - 4*s - 12= 0 :
<br /><b><font color='red'>1,3,3,9,-4,-12</font></b><br />
(6)s^6 + 2*s^5 + 8*s^4 + 12*s^3 + 20*s^2 + 16*s + 16= 0 :
<br /><b><font color='red'>1,2,8,12,20,16,16</font></b><br /></p>
<input id="inputParams" type="text" style="width: 367px" />
<input id="btnSubmit" type="button" value="Excute" />
<hr />
</body>
</html>
见今晚没别的事做, 就用来练习了一下JavaScript.
具体算法请见:
Module.9. Routh method,root locus_magnitude and phase equations.rar
测试网址:
Routh Method
JavaScript源代码:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Routh's Method</title>
<style type="text/css">
table td {
border: 1px solid;
padding: 5px;
}
</style>
<script type="text/javascript" language="javascript">
//跨浏览器的event辅助工具
var EventUtil = new Object;
//添加事件监听者
EventUtil.addEventHandler = function (oTarget, sEventType, fnHandler) {
if(oTarget.addEventListener) {
oTarget.addEventListener(sEventType, fnHandler, false);
}
else if (oTarget.attachEvent) {
oTarget.attachEvent("on" + sEventType, fnHandler);
}
else {
oTarget["on" + sEventType] = fnHandler;
}
}
var RouthArray = function(params) {
this._params = params;
this._count = this._params.length;
this._datas = [];
this._onImaginaryAxis = 0;
var index = 0;
for(var row = 0; row < 2; row++) {
this._datas[row] = [];
var count = Math.ceil(this._count/2);
for(var col = 0; col<count; col++) {
this._datas[row][col] = {};
this._datas[row][col].value = (this._params[index]!=null)?window.parseFloat(this._params[index]) : 0;
index += 2;
}
index = 1;
}
for(var row = 2; row < this._count; row++) {
this._datas[row] = [];
var zeroCount = 0;
for(var col = 0; this._datas[row-2][col+1]!=null && this._datas[row-2][col+1].value!=0; col++) {
if(this._datas[row-1][col+1]==null) {
this._datas[row-1][col+1] = {};
this._datas[row-1][col+1].value = 0;
}
this._datas[row][col] = {};
this._datas[row][col].value = (this._datas[row-1][0].value*this._datas[row-2][col+1].value
- this._datas[row-2][0].value*this._datas[row-1][col+1].value) / this._datas[row-1][0].value;
if(this._datas[row][col].value == 0) {
zeroCount++;
this._datas[row][col].isZero = true;
}
}
if(zeroCount == (Math.floor((this._count-row-1)/2)+1)) { //全为0
this._onImaginaryAxis++; //增加一对纯虚根, 即在虚轴上
var n = this._count-row;
var ct = Math.floor(n/2);
var r = row-1;
for(var c = 0; c<ct; c++) {
this._datas[row][c].value = this._datas[r][c].value*(n-2*c); //求导
}
}
else if(this._datas[row][0].value == 0 && (this._datas[row][1] != null && this._datas[row][1].value != 0)) { //第一列为0
this._datas[row][0].value = 0.00000001;
}
}
this.show();
}
RouthArray.prototype = {
show: function() {
var belowZero = this._datas[0][0].value > 0;
var signCngCount = 0;
var container = document.getElementById("container");
if(container) {
container.innerHTML = "";
}
else {
container = document.createElement("div");
container.id = "container";
document.body.appendChild(container);
}
var table = document.createElement("table");
container.appendChild(table);
for(var row=0; row<this._count; row++) {
// var tr = document.createElement("tr"); //IE不支持此方式
// table.appendChild(tr);
var tr = table.insertRow(-1);
var td = document.createElement("td");
td.innerHTML = "s"+(this._count-row-1)+":";
tr.appendChild(td);
for(var col=0; col<this._datas[row].length; col++) {
var td = document.createElement("td");
td.innerHTML = this._datas[row][col].value + (this._datas[row][col].isZero? "(0)" : "");
tr.appendChild(td);
}
if(belowZero) {
if(this._datas[row][0].value < 0) {
belowZero =!belowZero;
signCngCount++;
}
}
else {
if(this._datas[row][0].value > 0) {
belowZero =!belowZero;
signCngCount++;
}
}
}
var p = document.createElement("p");
if(this._onImaginaryAxis!=0) {
p.innerHTML = "虽然首列符号没有变化, 但在虚轴有<b><font color='red'>"+this._onImaginaryAxis
+"</font></b>对关于原点对称的根, 所以系统是<b><font color='red'>不稳定的</font></b>.";
}
else if(signCngCount == 0) {
p.innerHTML = "Since there are no sign changes in the first column, there are no closed-loop poles to the"+
" right of the imaginary axis, and the System is <b><font color='red'>stable</font></b>.<br />";
p.innerHTML += "由于首列符号没有变化, 则虚轴的右侧没有闭环极点, 所以系统是<b><font color='red'>稳定的</font></b>.";
}
else {
p.innerHTML = "Since there are <b><font color='red'>"+signCngCount
+"</font></b> sign changes in the first column, there are <b><font color='red'>"
+signCngCount+"</font></b> closed-loop poles to the"+
" right of the imaginary axis, and the System is <b><font color='red'>not stable</font></b>.<br />";
p.innerHTML += "由于首列符号变化了<b><font color='red'>"+signCngCount
+"</font></b>次, 则虚轴的右侧有<b><font color='red'>"+signCngCount
+"</font></b>对闭环极点, 所以系统是<b><font color='red'>不稳定的</font></b>.";
}
container.appendChild(p);
}
}
EventUtil.addEventHandler(window,"load", function() {
EventUtil.addEventHandler(document.getElementById("btnSubmit"),"click", function() {
new RouthArray(document.getElementById("inputParams").value.split(","));
});
});
</script>
</head>
<body>
<p>Test values: <br />
(1)s^4 + 2*s^3 + 3*s^2 + 2*s + 12 = 0 :
<br /><b><font color='red'>1,2,3,2,12</font></b><br />
(1)s^6 + 4*s^5 + 8*s^4 + 10*s^3 + 8*s^2 + 4*s + 1 = 0 :
<br /><b><font color='red'>1,4,8,10,8,4,1</font></b><br />
(3)s^4 + 3*s^3 + 4*s^2 + 12*s + 16 = 0 :
<br /><b><font color='red'>1,3,4,12,16</font></b><br />
(4)s^5 + s^4 + 2*s^3 + 2*s^2 + 3*s + 5 = 0 :
<br /><b><font color='red'>1,1,2,2,3,5</font></b><br />
(5)s^5 + 3*s^4 + 3*s^3 + 9*s^2 - 4*s - 12= 0 :
<br /><b><font color='red'>1,3,3,9,-4,-12</font></b><br />
(6)s^6 + 2*s^5 + 8*s^4 + 12*s^3 + 20*s^2 + 16*s + 16= 0 :
<br /><b><font color='red'>1,2,8,12,20,16,16</font></b><br /></p>
<input id="inputParams" type="text" style="width: 367px" />
<input id="btnSubmit" type="button" value="Excute" />
<hr />
</body>
</html>