Created
September 25, 2017 15:47
-
-
Save Kolobok12309/46bc2916f5881472818be8ce4887a2f5 to your computer and use it in GitHub Desktop.
testcalc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
</!DOCTYPE html> | |
<head> | |
<title>Calc</title> | |
$styles | |
</head> | |
<body> | |
<div id="result">test</div> | |
<div id="test"></div> | |
<form> | |
<fieldset id="matrix"> | |
<input type="number" id="0_0" class="inputi" oninput='check(0,0);'> | |
</fieldset> | |
$scripts | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var matrix = [ | |
[2,2,0,0,0], | |
[0,2,1,0,0], | |
[0,0,1,0,0], | |
[0,0,0,7,0], | |
[0,0,0,0,2] | |
]//Определяемая матрица | |
var typematrix = 4;//размерность матрицы | |
function matrix4(m) {//Готово | |
var result=0; | |
for (i=0;i<m.length;i++){ | |
result =+ m[0][i]*matrix3(minor(m,0,i)); | |
} | |
return result; | |
} | |
function matrix3(matr) {//Готово | |
var result = ((matr[0][0]*matr[1][1]*matr[2][2])+(matr[0][1]*matr[1][2]*matr[2][0])+(matr[0][2]*matr[1][0]*matr[2][1]))-((matr[0][2]*matr[1][1]*matr[2][0])+(matr[0][1]*matr[1][0]*matr[2][2])+(matr[0][0]*matr[1][2]*matr[2][1])); | |
return result; | |
} | |
function matrixmore (matr) { | |
var result; | |
if (matr.length ==1) {result = matr[0][0];} | |
else if (matr.length == 2) { result = matr[0][0]*matr[1][1]-matr[0][1]*matr[1][0];}// не точно | |
else if (matr.length == 3) { | |
result = matrix3(matr); | |
} | |
else { | |
result=0; | |
for (i=0;i<matr.length;i++){ | |
result =+ matr[0][i]*matrixmore(minor(matr,0,i)); | |
} | |
} | |
return result; | |
} | |
function matcreate(r) {//Готово | |
var result = [r]; | |
for (i=0;i<r;i++) { | |
result[i] = [r]; | |
} | |
return result; | |
} | |
function minor(mat,x,y) { //Готово | |
var result = matcreate(mat.length-1); | |
var l = 0; | |
for (i=0;i<mat.length;i++){ | |
if (y!=i){ | |
var m=0; | |
for(im=0;im<mat.length;im++){ | |
if (x!=im) { | |
result[l][m]=mat[i][im]; | |
m++; | |
} | |
} | |
l++; | |
} | |
} | |
return result; | |
} | |
function testmatrix(m) { | |
var div = getId('result'); | |
var l = m.length; | |
var state = 0; | |
for (i=0;i<l;i++) { | |
if (m[i].length != l) {state = 1;} | |
} | |
if (state) { | |
div.innerHTML = 'Error matrix'; | |
} else { | |
div.innerHTML = matrixmore(m); | |
} | |
} | |
var lastm = 0; | |
function getVal(x,y) { | |
return getId(x+'_'+y).value; | |
} | |
function getId(id) { | |
return document.getElementById(id); | |
} | |
//var matrix = matcreate(1); | |
function check(x,y) { | |
matrix[y][x] = getVal(x,y); | |
//crblock(x+1,y); | |
if ((x==lastm)||(y==lastm)) { | |
addnum(); | |
} | |
else { | |
var laststate = 0; | |
for (i=0;i<lastm;i++) { | |
if (!getVal(i,lastm)) { | |
laststate++; | |
} | |
if (!getVal(lastm,i)) { | |
laststate++; | |
} | |
} | |
if (laststate==lastm*2) { | |
removenum(); | |
} | |
}//Окончание цикла | |
testmatrix(matrix); | |
} | |
function crblock(x,y) { | |
var div = document.createElement('input'); | |
getId('matrix').appendChild(div); | |
div.className = 'inputi'; | |
div.id = x +'_' + y; | |
div.style.top = y*20+'px'; | |
div.style.left = x*50+'px'; | |
//div.oninput = check(x,y); | |
div.type = 'number'; | |
} | |
function addnum() { | |
for (i=0;i<lastm+1;i++) { | |
crblock(lastm+1,i);//столбец | |
crblock(i,lastm+1);//строка | |
} | |
crblock(lastm+1,lastm+1);//диагональ | |
lastm++; | |
} | |
function removenum() { | |
for (i=0;i<lastm;i++) { | |
getId(lastm+'_'+i).remove(); | |
getId(i+'_'+lastm).remove(); | |
} | |
getId(lastm+'_'+lastm).remove(); | |
lastm--; | |
} | |
//document.getElementById('0_0').oninput=function() {document.getElementById('test').innerHTML=getVal(0,0);}; | |
testmatrix(matrix); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#result { | |
position: absolute; | |
color: red; | |
font-size: 16vw; | |
left: 0; | |
top: 0; | |
width: 250px; | |
background-color: black; | |
} | |
#test { | |
position: absolute; | |
color: red; | |
left: 250px; | |
top: 0; | |
height: 20px; | |
width: 50px; | |
} | |
#matrix { | |
position: absolute; | |
left: 0; | |
top: 130px; | |
} | |
.inputi { | |
position: absolute; | |
height: 20px; | |
width: 50px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment