diff --git a/gallery/example2.pdf b/gallery/example2.pdf index 97082aa..e35280d 100644 --- a/gallery/example2.pdf +++ b/gallery/example2.pdf @@ -796,8 +796,8 @@ endobj 12 0 obj << /Creator (Typst 0.11.0) - /CreationDate (D:20240624231411Z) - /ModDate (D:20240624231411Z) + /CreationDate (D:20240625141015Z) + /ModDate (D:20240625141015Z) >> endobj @@ -808,7 +808,7 @@ endobj /Subtype /XML >> stream -Typst 0.11.02024-06-24T23:14:11Z2024-06-24T23:14:11Z1application/pdfenWHmj50Lk4HtEPB9JVQdHrg==WHmj50Lk4HtEPB9JVQdHrg==proof1.7 +Typst 0.11.02024-06-25T14:10:15Z2024-06-25T14:10:15Z1application/pdfen5nsOW2SnG+nAEaNXgt0fwA==5nsOW2SnG+nAEaNXgt0fwA==proof1.7 endstream endobj @@ -851,7 +851,7 @@ trailer /Size 15 /Root 14 0 R /Info 12 0 R - /ID [(WHmj50Lk4HtEPB9JVQdHrg==) (WHmj50Lk4HtEPB9JVQdHrg==)] + /ID [(5nsOW2SnG+nAEaNXgt0fwA==) (5nsOW2SnG+nAEaNXgt0fwA==)] >> startxref 157447 diff --git a/gallery/example3.pdf b/gallery/example3.pdf new file mode 100644 index 0000000..78f7120 Binary files /dev/null and b/gallery/example3.pdf differ diff --git a/gallery/example3.typ b/gallery/example3.typ new file mode 100644 index 0000000..af5e7b3 --- /dev/null +++ b/gallery/example3.typ @@ -0,0 +1,27 @@ +#import "/src/lib.typ": * + +#let A = mat.mat( + (3, -3, -1, 2, -9), + (1, -1, 2, -1, -6), + (1, -1, 1, 1, -6), + (-1, 1, -1, -2, 7) +) + +#let b = vec.vec(13, -6, 1, -3) + +#let A2 = mat.mul-row(A, 2, 3) +#let A3 = mat.div-row(A, 1, 2) +#let A4 = mat.add-row(A, 2, 3, f: 2) + +$ + A = #mat.display(A) quad b = #vec.display(b)\ + A_2 = #mat.display(A2)\ + A_3 = #mat.display(A3)\ + A_4 = #mat.display(A4)\ +$ + +#let E = gauss.echelon(A) + +$ + E = #mat.display(E) +$ diff --git a/src/gauss.typ b/src/gauss.typ new file mode 100644 index 0000000..caae58c --- /dev/null +++ b/src/gauss.typ @@ -0,0 +1,53 @@ +#import "mat.typ" as _mat + +#let find-next-non-null(mat, x: 0, start-y: 0) = { + for y in range(start-y, mat.h) { + if mat.rows.at(y).at(x) != 0 { + return y + } + } + return none +} + + +#let echelon(mat) = { + _mat._check(mat) + let dim = calc.min(mat.w, mat.h) + let mat = mat + + // Gauss + for i in range(dim) { + let pivot = mat.rows.at(i).at(i) + + // Pivot != 0 -> divide to get 1 + if pivot != 0 { + mat = _mat.div-row(mat, i, pivot) + + } else { + let y = find-next-non-null(mat, x: i, start-y: i) + if y != none { + mat = _mat.add-row(mat, i, y, f: 1 / mat.rows.at(y).at(i)) + } + } + + // Make all rows below 0 + for y in range(i + 1, mat.h) { + mat = _mat.add-row(mat, y, i, f: -mat.rows.at(y).at(i)) + } + } + + // Jordan + for y in range(dim) { + for x in range(y + 1, dim) { + mat = _mat.add-row(mat, y, x, f: -mat.rows.at(y).at(x)) + } + } + + return _mat.round(mat) +} + +// solver = Solver(matrix, constants) +// solver.solve() + +// gauss = Gaussificator(matrix, constants) +// gauss.echelon() \ No newline at end of file