lab5
This commit is contained in:
BIN
Лаб5/Задание/lab5.pdf
Normal file
BIN
Лаб5/Задание/lab5.pdf
Normal file
Binary file not shown.
30
Лаб5/Сайт/src/index.html
Normal file
30
Лаб5/Сайт/src/index.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Решение задачи</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Введите параметры</h2>
|
||||
|
||||
<label for="rows">Количество строк матрицы:</label>
|
||||
<input type="number" id="rows" placeholder="Количество строк"><br><br>
|
||||
|
||||
<label for="cols">Количество столбцов матрицы:</label>
|
||||
<input type="number" id="cols" placeholder="Количество столбцов"><br><br>
|
||||
|
||||
<label for="min">Минимальное значение:</label>
|
||||
<input type="number" id="min" placeholder="Минимальное значение"><br><br>
|
||||
|
||||
<label for="max">Максимальное значение:</label>
|
||||
<input type="number" id="max" placeholder="Максимальное значение"><br><br>
|
||||
|
||||
<button onclick="calculate()">Рассчитать</button>
|
||||
|
||||
<h2>Результаты</h2>
|
||||
|
||||
<div id="output"></div>
|
||||
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
56
Лаб5/Сайт/src/script.js
Normal file
56
Лаб5/Сайт/src/script.js
Normal file
@@ -0,0 +1,56 @@
|
||||
function average(arr) {
|
||||
return arr.reduce((acc, val) => acc + val, 0) / arr.length;
|
||||
}
|
||||
|
||||
function generateRandomArray(length, min, max) {
|
||||
return Array.from({ length }, () => Math.random() * (max - min + 1) + min);
|
||||
}
|
||||
|
||||
function calculate() {
|
||||
const rows = parseInt(document.getElementById('rows').value);
|
||||
const cols = parseInt(document.getElementById('cols').value);
|
||||
const min = parseInt(document.getElementById('min').value);
|
||||
const max = parseInt(document.getElementById('max').value);
|
||||
|
||||
const M1 = Array.from({ length: rows }, () =>
|
||||
generateRandomArray(cols, min, max)
|
||||
);
|
||||
const M2 = Array.from({ length: rows }, () =>
|
||||
generateRandomArray(cols, min, max)
|
||||
);
|
||||
|
||||
const V1 = M1.map((row) => average(row));
|
||||
const V2 = M2.map((row) => average(row));
|
||||
|
||||
const sortedV1 = V1.slice().sort((a, b) => a - b);
|
||||
const sortedV2 = V2.slice().sort((a, b) => b - a);
|
||||
|
||||
const filteredV1 = sortedV1.filter((val) => Math.floor(val) % 2 !== 0);
|
||||
const filteredV2 = sortedV2.filter((val) => Math.floor(val) % 2 === 0);
|
||||
|
||||
const output = document.getElementById('output');
|
||||
output.innerHTML = `
|
||||
<h3>Изначальные матрицы:</h3>
|
||||
<pre>M1:\n${matrixToString(M1)}</pre>
|
||||
<pre>M2:\n${matrixToString(M2)}</pre>
|
||||
<h3>Векторы средних значений:</h3>
|
||||
<pre>Вектор V1: ${vectorToString(V1)}</pre>
|
||||
<pre>Вектор V2: ${vectorToString(V2)}</pre>
|
||||
<h3>Отсортированные векторы:</h3>
|
||||
<pre>Отсортированный вектор V1: ${vectorToString(sortedV1)}</pre>
|
||||
<pre>Отсортированный вектор V2: ${vectorToString(sortedV2)}</pre>
|
||||
<h3>Отфильтрованные векторы:</h3>
|
||||
<pre>Отфильтрованный вектор V1: ${vectorToString(filteredV1)}</pre>
|
||||
<pre>Отфильтрованный вектор V2: ${vectorToString(filteredV2)}</pre>
|
||||
`;
|
||||
}
|
||||
|
||||
function matrixToString(matrix) {
|
||||
return matrix
|
||||
.map((row) => row.map((val) => val.toFixed(4)).join('\t'))
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
function vectorToString(vector) {
|
||||
return `[${vector.map((val) => val.toFixed(4)).join(', ')}]`;
|
||||
}
|
||||
Reference in New Issue
Block a user