-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
164 lines (135 loc) · 5.45 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Лабораторна робота №2</title>
<link rel="stylesheet" href="css/style.css" type="text/css"/>
<link rel="stylesheet" href="css/bootstrap.css" type="text/css"/>
<link rel="stylesheet" href="css/bootstrap-theme.min.css" type="text/css"/>
<script ulr="js/bootstrap.min.js"></script>
<style>
.result{
margin-top:20px;
}
#show-good{
display:none;
}
#show-not-good{
display:none;
}
</style>
</head>
<body>
<div class="wrapper-body"><div class="alert alert-info" role="alert"><h2>Розв'язання СЛАР методом Гаусса</h2></div>
<div class="input-positions">
<H5>1-ий стовпець</H5>
<form action="" id="first-columns">
<input type="" class="form-control" placeholder="X(1;1)" value="4">
<input type="" class="form-control" placeholder="X(1;2)" value="3">
<input type="" class="form-control" placeholder="X(1;3)" value="100">
<input type="" class="form-control" placeholder="X(1;4)" value="2">
</form>
</div>
<div class="input-positions">
<H5>2-ий стовпець</H5>
<form action="" id="second-columns">
<input type="" class="form-control" placeholder="X(2;1)" value="1000">
<input type="" class="form-control" placeholder="X(2;2)" value="-1">
<input type="" class="form-control" placeholder="X(2;3)" value="-3">
<input type="" class="form-control" placeholder="X(2;4)" value="2">
</form>
</div>
<div class="input-positions">
<H5>3-тій стовпець</H5>
<form action="" id="three-columns">
<input type="" class="form-control" placeholder="X(3;1)" value="2">
<input type="" class="form-control" placeholder="X(3;2)" value="1">
<input type="" class="form-control" placeholder="X(3;3)" value="-2">
<input type="" class="form-control" placeholder="X(3;4)" value="0">
</form>
</div>
<div class="input-positions">
<H5>4-ий стовпець</H5>
<form action="" id="four-columns">
<input type="" class="form-control" placeholder="X(4;1)" value="3">
<input type="" class="form-control" placeholder="X(4;2)" value="-3">
<input type="" class="form-control" placeholder="X(4;3)" value="0">
<input type="" class="form-control" placeholder="X(4;4)" value="-1">
</form>
</div>
<div class="input-positions">
<H5>Права частина</H5>
<form action="" id="right-columns">
<input type="" class="form-control" placeholder="" value="5">
<input type="" class="form-control" placeholder="" value="-1">
<input type="" class="form-control" placeholder="" value="-3">
<input type="" class="form-control" placeholder="" value="-1">
</form>
</div>
<button type="button" class="btn btn-primary" onclick="MathResult()">Порахувати результат</button>
<button type="button" class="btn btn-info" onclick="ByZerro()">Скинути</button>
<div class="result">
<div class="alert alert-success" id="show-good" role="alert"></div>
<div class="alert alert-danger" id="show-not-good" role="alert"></div>
</div>
</div>
<Script>
function MathResult(){
var MassAll = [];
var MassRight = [];
document.getElementById('show-good').style.display="none";
document.getElementById('show-not-good').style.display="none";
for (var i = 0; i < 4; i++){
MassAll[i] = []; var x=0;
for (var j = 0; j < 5; j++){
MassAll[i][j] = document.getElementsByTagName('input')[i+x].value;
x=x+4;
if (j==4) MassRight.push(MassAll[i][j]);
}}
var X = [];
var R=0;
for (var k = 0; k < 4; k++) {
for (var i = 0; i < 4; i++) {
if (i !== k){
R = MassAll[i][k] / MassAll[k][k];
for (var j = k; j < 4; j++) {
MassAll[i][j] = MassAll[i][j] - MassAll[k][j]*R;
}
MassRight[i] = MassRight[i]-MassRight[k] * R;
}
}
}
MassAll[0][1] = 0;
MassAll[0][4] = MassRight[0];
MassAll[1][4] = MassRight[1];
MassAll[2][4] = MassRight[2];
MassAll[3][4] = MassRight[3];
X[0] = MassRight[0] / MassAll[0][0];
X[1] = MassRight[1] / MassAll[1][1];
X[2] = MassRight[2] / MassAll[2][2];
X[3] = MassRight[3] / MassAll[3][3];
if ((!isNaN(X[0]))&(!isNaN(X[1]))&(!isNaN(X[2]))&(!isNaN(X[3]))){
var SuccessDiv = document.getElementsByClassName("alert alert-success")[0];
var GoodAlertText = "<b>"+"Успішно!"+"</b>"+" Ось ваші розв'язки:"+" X1="+X[0].toFixed(4)+", X2="+X[1].toFixed(4)+", X3="+X[2].toFixed(4)+", X4="+X[3].toFixed(4)+".";
SuccessDiv.innerHTML = GoodAlertText;
document.getElementById('show-good').style.display="inline";
}
else{
var NotSuccessDiv = document.getElementsByClassName("alert alert-danger")[0];
var NotGoodAlertText = "<b>"+"Упс!"+"</b>"+" Щось пішло не так! Уважно перевірте введені дані!";
NotSuccessDiv.innerHTML = NotGoodAlertText;
document.getElementById('show-not-good').style.display="inline";
}
delete MassAll,MassRight,MathResult,X,SuccessDiv,GoodAlertText,NotSuccessDiv,NotGoodAlertText,R,i,k,j,x;
}
function ByZerro(){
for(var i=0; i<20;i++){
document.getElementsByTagName('input')[i].value="";
}
setTimeout("alert('Значення успішно очищені')", 150);
document.getElementById('show-not-good').style.display="none";
document.getElementById('show-good').style.display="none";
}
</Script>
</body>
</html>