diff --git a/.gitignore b/.gitignore index 403adbc..c1f3bb7 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ npm-debug.log* yarn-debug.log* yarn-error.log* pnpm-debug.log* +server.log # Editor directories and files .idea diff --git a/src/App.vue b/src/App.vue index be939a4..26aa3e6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,20 +1,80 @@ - - - \ No newline at end of file +provide('matrixSize', matrixSize); +provide('matrixA', matrixA); +provide('matrixB', matrixB); +provide('vectorB', vectorB); + diff --git a/src/components/AppFooter.vue b/src/components/AppFooter.vue new file mode 100644 index 0000000..f8bcfaa --- /dev/null +++ b/src/components/AppFooter.vue @@ -0,0 +1,8 @@ + + + diff --git a/src/components/AppHeader.vue b/src/components/AppHeader.vue new file mode 100644 index 0000000..875f8bc --- /dev/null +++ b/src/components/AppHeader.vue @@ -0,0 +1,13 @@ + + + diff --git a/src/components/MatrixInput.vue b/src/components/MatrixInput.vue index fbc07de..8bce742 100644 --- a/src/components/MatrixInput.vue +++ b/src/components/MatrixInput.vue @@ -1,439 +1,129 @@ - - - \ No newline at end of file diff --git a/src/components/MatrixOperations.vue b/src/components/MatrixOperations.vue index 1cb9fbf..7149b2b 100644 --- a/src/components/MatrixOperations.vue +++ b/src/components/MatrixOperations.vue @@ -1,132 +1,85 @@ - - function subtractMatrices() { - try { - const result = math.subtract(props.matrixA, props.matrixB) - emit('operation-result', result) - } catch (error) { - console.error('Error subtracting matrices:', error) - } - } - - function multiplyMatrices() { - try { - const result = math.multiply(props.matrixA, props.matrixB) - emit('operation-result', result) - } catch (error) { - console.error('Error multiplying matrices:', error) - } - } - - return { - // determinant, - // operationResult, - calculateDeterminant, - addMatrices, - subtractMatrices, - multiplyMatrices - } - } + diff --git a/src/components/MatrixResult.vue b/src/components/MatrixResult.vue new file mode 100644 index 0000000..aaee27a --- /dev/null +++ b/src/components/MatrixResult.vue @@ -0,0 +1,89 @@ + + + + + diff --git a/src/components/OperationButtons.vue b/src/components/OperationButtons.vue deleted file mode 100644 index 8cb7770..0000000 --- a/src/components/OperationButtons.vue +++ /dev/null @@ -1,79 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/composables/useMatrixOperations.js b/src/composables/useMatrixOperations.js index f2852a2..7908dfd 100644 --- a/src/composables/useMatrixOperations.js +++ b/src/composables/useMatrixOperations.js @@ -1,93 +1,176 @@ -import * as math from 'mathjs' +import { ref, watch } from 'vue'; +import * as math from 'mathjs'; -export function useMatrixOperations(props, emit) { - async function calculateDeterminant() { +export function useMatrixOperations() { + const matrixSize = ref(3); + const matrixA = ref(createMatrix(matrixSize.value)); + const matrixB = ref(createMatrix(matrixSize.value)); + const vectorB = ref(Array(matrixSize.value).fill(0)); + const operationResult = ref([]); + const determinant = ref(null); + const solution = ref(null); + const eigenvalues = ref(null); + const lu = ref(null); + const qr = ref(null); + const error = ref(null); + + function createMatrix(size) { + return Array.from({ length: size }, () => Array(size).fill(0)); + } + + function resetResults() { + operationResult.value = []; + determinant.value = null; + solution.value = null; + eigenvalues.value = null; + lu.value = null; + qr.value = null; + error.value = null; + } + + watch(matrixSize, (newSize) => { + if (newSize > 0 && newSize <= 10) { + matrixA.value = createMatrix(newSize); + matrixB.value = createMatrix(newSize); + vectorB.value = Array(newSize).fill(0); + resetResults(); + } + }); + + function calculateDeterminant() { + resetResults(); try { - const det = math.det(props.matrixA) - emit('determinant', det) - } catch (error) { - console.error('Error calculating determinant:', error) + determinant.value = math.det(matrixA.value); + } catch (err) { + error.value = 'Error calculating determinant: ' + err.message; } } - async function addMatrices() { + function addMatrices() { + resetResults(); try { - const result = math.add(props.matrixA, props.matrixB) - emit('operation-result', result) - } catch (error) { - console.error('Error adding matrices:', error) + operationResult.value = math.add(matrixA.value, matrixB.value); + } catch (err) { + error.value = 'Error adding matrices: ' + err.message; } } - async function subtractMatrices() { + function subtractMatrices() { + resetResults(); try { - const result = math.subtract(props.matrixA, props.matrixB) - emit('operation-result', result) - } catch (error) { - console.error('Error subtracting matrices:', error) + operationResult.value = math.subtract(matrixA.value, matrixB.value); + } catch (err) { + error.value = 'Error subtracting matrices: ' + err.message; } } - async function multiplyMatrices() { + function multiplyMatrices() { + resetResults(); try { - const result = math.multiply(props.matrixA, props.matrixB) - emit('operation-result', result) - } catch (error) { - console.error('Error multiplying matrices:', error) + operationResult.value = math.multiply(matrixA.value, matrixB.value); + } catch (err) { + error.value = 'Error multiplying matrices: ' + err.message; } } - async function solveLinearEquations() { + function solveLinearEquations() { + resetResults(); try { - const b = math.matrix(props.vectorB.map(x => [x])) - const solution = math.lusolve(props.matrixA, b).toArray().flat() - emit('solution', solution) - } catch (error) { - console.error('Error solving equations:', error) + const b = math.matrix(vectorB.value.map(x => [x])); + solution.value = math.lusolve(matrixA.value, b).toArray().flat(); + } catch (err) { + error.value = 'Error solving equations: ' + err.message; } } - async function calculateEigenvalues() { + function calculateEigenvalues() { + resetResults(); try { - const result = math.eigs(props.matrixA) - const eigenvalues = result.values.map(v => - typeof v === 'number' ? v.toFixed(4) : + const result = math.eigs(matrixA.value); + eigenvalues.value = result.values.map(v => + typeof v === 'number' ? v.toFixed(4) : `${v.re.toFixed(4)} + ${v.im.toFixed(4)}i` - ).join(', ') - emit('eigenvalues', eigenvalues) - } catch (error) { - console.error('Error calculating eigenvalues:', error) + ).join(', '); + } catch (err) { + error.value = 'Error calculating eigenvalues: ' + err.message; } } - async function luDecomposition() { + function luDecomposition() { + resetResults(); try { - const result = math.lup(props.matrixA) - const lu = { + const result = math.lup(matrixA.value); + lu.value = { L: result.L.toArray(), U: result.U.toArray(), P: result.p.map(i => i + 1) - } - emit('decomposition', { type: 'lu', data: lu }) - } catch (error) { - console.error('Error performing LU decomposition:', error) + }; + } catch (err) { + error.value = 'Error performing LU decomposition: ' + err.message; } } - async function qrDecomposition() { + function qrDecomposition() { + resetResults(); try { - const result = math.qr(props.matrixA) - const qr = { + const result = math.qr(matrixA.value); + qr.value = { Q: result.Q.toArray(), R: result.R.toArray() + }; + } catch (err) { + error.value = 'Error performing QR decomposition: ' + err.message; + } + } + + function saveMatrix() { + try { + localStorage.setItem('savedMatrixA', JSON.stringify(matrixA.value)); + alert('Matrix A saved successfully!'); + } catch (err) { + error.value = 'Error saving matrix: ' + err.message; + } + } + + function loadMatrix() { + try { + const saved = localStorage.getItem('savedMatrixA'); + if (saved) { + const parsedMatrix = JSON.parse(saved); + matrixA.value = parsedMatrix; + matrixSize.value = parsedMatrix.length; + resetResults(); + alert('Matrix A loaded successfully!'); + } else { + alert('No matrix saved yet.'); + } + } catch (err) { + error.value = 'Error loading matrix: ' + err.message; } - emit('decomposition', { type: 'qr', data: qr }) - } catch (error) { - console.error('Error performing QR decomposition:', error) + } + + + function formatDecomposition(decomp) { + let result = ''; + for (const [key, value] of Object.entries(decomp)) { + result += `${key}:\n`; + result += math.format(value, { precision: 4 }) + '\n\n'; } + return result; } return { + matrixSize, + matrixA, + matrixB, + vectorB, + operationResult, + determinant, + solution, + eigenvalues, + lu, + qr, + error, calculateDeterminant, addMatrices, subtractMatrices, @@ -95,6 +178,9 @@ export function useMatrixOperations(props, emit) { solveLinearEquations, calculateEigenvalues, luDecomposition, - qrDecomposition - } -} \ No newline at end of file + qrDecomposition, + saveMatrix, + loadMatrix, + formatDecomposition + }; +}