diff --git a/Лаб5/Задание/lab5.pdf b/Лаб5/Задание/lab5.pdf new file mode 100644 index 0000000..88ac162 Binary files /dev/null and b/Лаб5/Задание/lab5.pdf differ diff --git a/Лаб5/Сайт/src/index.html b/Лаб5/Сайт/src/index.html new file mode 100644 index 0000000..8f3938a --- /dev/null +++ b/Лаб5/Сайт/src/index.html @@ -0,0 +1,30 @@ + + + + + Решение задачи + + +

Введите параметры

+ + +

+ + +

+ + +

+ + +

+ + + +

Результаты

+ +
+ + + + diff --git a/Лаб5/Сайт/src/script.js b/Лаб5/Сайт/src/script.js new file mode 100644 index 0000000..d07a7f7 --- /dev/null +++ b/Лаб5/Сайт/src/script.js @@ -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 = ` +

Изначальные матрицы:

+
M1:\n${matrixToString(M1)}
+
M2:\n${matrixToString(M2)}
+

Векторы средних значений:

+
Вектор V1: ${vectorToString(V1)}
+
Вектор V2: ${vectorToString(V2)}
+

Отсортированные векторы:

+
Отсортированный вектор V1: ${vectorToString(sortedV1)}
+
Отсортированный вектор V2: ${vectorToString(sortedV2)}
+

Отфильтрованные векторы:

+
Отфильтрованный вектор V1: ${vectorToString(filteredV1)}
+
Отфильтрованный вектор V2: ${vectorToString(filteredV2)}
+ `; +} + +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(', ')}]`; +}