Skip to content

Instantly share code, notes, and snippets.

@dertst
Last active April 30, 2019 05:48
Show Gist options
  • Save dertst/c202883f7b4a03637a8bb5f484526fa4 to your computer and use it in GitHub Desktop.
Save dertst/c202883f7b4a03637a8bb5f484526fa4 to your computer and use it in GitHub Desktop.
матрицы
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Лабораторная работа№ 2</title>
</head>
<body>
<head>Свойства отношения матрицы nxn</head>
<form action="" method="post">
Матрица отношения: <textarea rows="6" name="mat"></textarea>
<br>
<input type="submit" name="sub" value="показать свойства">
</form>
<?php
ini_set('display_errors', 'Off');
if (isset($_POST['sub'])) {
$ind = 0;
$str = explode("\n", htmlspecialchars($_POST ['mat']));
$n = count($str);
for ($i = 0; $i < $n; $i++) {
$el[$i] = explode(' ', $str[$i]);
}
for ($i = 0; $i < $n; $i++) {
}
for ($i = 0; $i < $n; $i++) {
if ($el[$i][$i] == 0) {
$ind = 1;
break;
}
}
if ($ind) {
echo 'Нерефлексивна';
} else {
echo 'Рефлексивна';
}
echo '<br>';
$ind = 0;
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n; $j++) {
if ($el[$i][$j] != $el[$j][$i]) {
$ind = 1;
break;
}
}
}
if ($ind) {
echo 'Acимметрична';
} else {
echo 'Cимметрична';
}
$ind = 0;
echo '<br>';
$temp = 0;
$el1 = array();
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n; $j++) {
$el1[$i][$j] = 0;
}
}
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n; $j++) {
for ($s = 0; $s < $n; $s++) {
$el1[$i][$j] = $temp + ($el[$s][$i] * $el[$j][$s]);
$temp = $el1[$i][$j];
}
$temp = 0;
}
}
$ind = 0;
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n; $j++) {
if ($el[$i][$j] != $el1[$i][$j]) {
$ind = 1;
break;
}
}
}
if ($ind) {
echo 'Нетранзитивна';
} else 'Транзитивна';
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment