Пример #1
0
<?php

if (isset($_POST['size'])) {
    $size = $_POST['size'];
    if (!is_numeric($size)) {
        write_to_errors_file('Error: Entered matrix size is not numerical.');
        header('Location:/views/matrix_size_input.php/?dir=' . __DIR__);
    } else {
        if ($size >= 1) {
            require __DIR__ . '/views/matrix_input.php';
            matrix_input($size);
        } else {
            write_to_errors_file('Error: Entered matrix size is less then 1.');
            header('Location:/views/matrix_size_input.php/?dir=' . __DIR__);
        }
    }
} else {
    write_to_errors_file('Error: Matrix size is not specified.');
    header('Location:/views/matrix_size_input.php/?dir=' . __DIR__);
}
function write_to_errors_file($str)
{
    require __DIR__ . '/modules/matrix_file_write.php';
    $path = __DIR__ . '/errors.php';
    $errors = error_read_file($path);
    $errors[] = $str;
    error_write_file($errors, $path);
    return;
}
Пример #2
0
             }
         }
         $i++;
     } else {
         $l = 1;
         // line exchange
         do {
             $sch = $sch + 1;
             for ($j = $i; $j < 2 * $size; $j++) {
                 $b = $matrix[$i][$j];
                 $matrix[$i][$j] = $matrix[$i + $l][$j];
                 $matrix[$i + $l][$j] = $b;
             }
             $l++;
             if ($l > $size - $i - 1) {
                 write_to_errors_file('Matrix determinant equals to 0.' . "</br>" . 'Inverse matrix could not be found.' . "</br>");
                 $pr = false;
             }
         } while ($matrix[$i][$i] == 0 && $pr);
     }
 } while ($i < $size && $pr);
 if ($pr) {
     $det = 1;
     for ($i = 0; $i < $size; $i++) {
         $det = $det * $matrix[$i][$i];
     }
     $det = $det * st($sch);
     // calculation of elements of the inverse matrix
     //    $c = 0;
     for ($i = 0; $i < $size; $i++) {
         for ($j = $size - 1; $j > -1; $j--) {