diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index 9e26c79..9003818 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx @@ -1,36 +1,159 @@ +import { useEffect, useState } from "react"; +import Button from "../Button/Button"; import Matrix from "../Matrix/Matrix"; import SelectSize from "../SelectSize/SelectSize"; +import Panel from "../Panel/Panel"; +import Result from "../Result/Result"; function App() { + const [sizeMatrix, setSizeMatrix] = useState({ x: 2, y: 2 }); + const [range, setRange] = useState({ from: 0, to: 99 }); + const [matrixA, setMatrixA] = useState([ + [0, 0], + [0, 0], + ]); + const [matrixB, setMatrixB] = useState([0, 0]); + + useEffect(() => { + updateMatrix(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [sizeMatrix]); + + const updateMatrix = () => { + setMatrixA((current) => { + const newMatrix: number[][] = []; + + for (let i = 0; i < sizeMatrix.y; i++) { + const newRow: number[] = []; + for (let j = 0; j < sizeMatrix.x; j++) { + newRow.push(current[i]?.[j] || 0); + } + newMatrix.push(newRow); + } + + return newMatrix; + }); + + setMatrixB((current) => { + const newMatrix: number[] = []; + + for (let i = 0; i < sizeMatrix.y; i++) { + newMatrix.push(current[i] || 0); + } + + return newMatrix; + }); + }; + + const generateMatrix = () => { + setMatrixA(() => { + const newMatrix: number[][] = []; + + for (let i = 0; i < sizeMatrix.y; i++) { + const newRow: number[] = []; + for (let j = 0; j < sizeMatrix.x; j++) { + newRow.push( + Math.round(Math.random() * (range.to - range.from)) + range.from, + ); + } + newMatrix.push(newRow); + } + + return newMatrix; + }); + + setMatrixB(() => { + const newMatrix: number[] = []; + + for (let i = 0; i < sizeMatrix.y; i++) { + newMatrix.push( + Math.round(Math.random() * (range.to - range.from)) + range.from, + ); + } + + return newMatrix; + }); + }; + return ( <> -
-
-

Input matrix

- -
-

Size:

- -

x

- -
- - {/*
- -
*/} +
+

Jordan elimination method

+
+
+
+ +

+ Matrix A & B +

+ +
+
+
+

Size:

+ + setSizeMatrix({ + x: sizeMatrix.x, + y: Number(e.currentTarget.value), + }), + }} + /> +

x

+ + setSizeMatrix({ + x: Number(e.currentTarget.value), + y: sizeMatrix.y, + }), + }} + /> +
+
+

From

+ { + setRange({ + from: Number(e.currentTarget.value), + to: range.to, + }); + }} + /> +

to

+ { + setRange({ + from: range.from, + to: Number(e.currentTarget.value), + }); + }} + /> +
+
+
+ {/*

A

*/} + +
+
+ {/*

B

*/} + +
+
+
+
+
+

+ +

diff --git a/src/components/Button/Button.tsx b/src/components/Button/Button.tsx new file mode 100644 index 0000000..edb1196 --- /dev/null +++ b/src/components/Button/Button.tsx @@ -0,0 +1,22 @@ +import { FC, ButtonHTMLAttributes, DetailedHTMLProps } from "react"; + +type buttonProps = DetailedHTMLProps< + ButtonHTMLAttributes, + HTMLButtonElement +>; + +const Button: FC = (buttonProps) => { + return ( + + ); +}; + +export default Button; diff --git a/src/components/Matrix/Matrix.tsx b/src/components/Matrix/Matrix.tsx index 6ab8d53..13018b3 100644 --- a/src/components/Matrix/Matrix.tsx +++ b/src/components/Matrix/Matrix.tsx @@ -1,24 +1,21 @@ import { FC } from "react"; -// const styles = stylex.create({ -// table: { -// border: "1px solid", -// paddingHorizontal: "0.5rem", -// }, -// }); - -const Matrix: FC<{ value: number[][] }> = ({ value }) => { +const Matrix: FC<{ value: number[][] | number[] }> = ({ value }) => { return ( <> - {value.map((row, rowIndex) => ( - - {row.map((value, colIndex) => ( - - ))} + {value.map((rowVal, rowIndex) => ( + + {Array.isArray(rowVal) ? ( + rowVal.map((colVal, colIndex) => ( + + )) + ) : ( + + )} ))} diff --git a/src/components/Panel/Panel.tsx b/src/components/Panel/Panel.tsx new file mode 100644 index 0000000..8ab886b --- /dev/null +++ b/src/components/Panel/Panel.tsx @@ -0,0 +1,23 @@ +import { FC, ReactNode } from "react"; + +interface IPanel { + children?: ReactNode; + className?: string; +} + +const Panel: FC = ({ children, className }) => { + return ( +
+ {children} +
+ ); +}; + +export default Panel; diff --git a/src/components/Result/Result.tsx b/src/components/Result/Result.tsx new file mode 100644 index 0000000..aa00bb2 --- /dev/null +++ b/src/components/Result/Result.tsx @@ -0,0 +1,84 @@ +import { FC } from "react"; +import Matrix from "../Matrix/Matrix"; +import inverseMatrix from "../../functions/inverseMatrix"; +import { roundedMatrix, roundedRow } from "../../functions/utils"; +import matrixRank from "../../functions/matrixRank"; +import solveLinearSystem from "../../functions/solveLinearSystem"; + +interface IResult { + matrixA: number[][]; + matrixB: number[]; +} + +const Result: FC = ({ matrixA, matrixB }) => { + const invertedMatrix = inverseMatrix(matrixA); + const rank = matrixRank(matrixA); + const solution = solveLinearSystem(matrixA, matrixB); + + return ( +
+

Finding the inverse matrix.

+ -------------------------------------------------- + {invertedMatrix ? ( + <> + Inverse matrix: + + + ) : ( + <> + The inverse matrix was not found. + + )} + +

Finding the rank of a matrix.

+ -------------------------------------------------- + Matrix rank: {rank} + +

+ Solution of the system of linear equations. +

+ -------------------------------------------------- + {solution ? ( + <> + Solving the system of linear equations: + + + ) : ( + <> + A matrix does not have an inverse matrix. + + )} +
+ // <> + // {invertedMatrix ? ( + // <> + //

Inverse matrix:

+ // + // + // ) : ( + // <> + //

+ // The matrix is not square, the inverse matrix does not exist. + //

+ // + // )} + + //

Matrix rank: {rank}

+ + // {solution ? ( + // <> + //

Solving the system of linear equations:

+ // + // + // ) : ( + // <> + //

+ // A matrix does not have an inverse matrix. + //

+ // + // )} + // + ); +}; + +export default Result; diff --git a/src/components/SelectSize/SelectSize.tsx b/src/components/SelectSize/SelectSize.tsx index 1531e9b..0b6320a 100644 --- a/src/components/SelectSize/SelectSize.tsx +++ b/src/components/SelectSize/SelectSize.tsx @@ -3,16 +3,21 @@ import { FC, HTMLProps } from "react"; interface ISelectSize { selectProps?: HTMLProps; optionProps?: HTMLProps; + // selectProps?: DetailedHTMLProps, HTMLSelectElement>; + // optionProps?: DetailedHTMLProps, HTMLOptionElement>; } -const SelectSize: FC = (selectProps, optionProps) => { +const SelectSize: FC = ({ selectProps, optionProps }) => { return ( <>
- {value} -
+ {colVal} + {rowVal}