added Gauss-Jordan

This commit is contained in:
Louis Heredero 2024-06-25 17:07:24 +02:00
parent d880ebd2aa
commit cfda844ebc
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
4 changed files with 84 additions and 4 deletions

View File

@ -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
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="xmp-writer"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:xmpTPg="http://ns.adobe.com/xap/1.0/t/pg/" xmlns:pdf="http://ns.adobe.com/pdf/1.3/" ><xmp:CreatorTool>Typst 0.11.0</xmp:CreatorTool><xmp:CreateDate>2024-06-24T23:14:11Z</xmp:CreateDate><xmp:ModifyDate>2024-06-24T23:14:11Z</xmp:ModifyDate><xmpTPg:NPages>1</xmpTPg:NPages><dc:format>application/pdf</dc:format><dc:language><rdf:Bag><rdf:li>en</rdf:li></rdf:Bag></dc:language><xmpMM:DocumentID>WHmj50Lk4HtEPB9JVQdHrg==</xmpMM:DocumentID><xmpMM:InstanceID>WHmj50Lk4HtEPB9JVQdHrg==</xmpMM:InstanceID><xmpMM:RenditionClass>proof</xmpMM:RenditionClass><pdf:PDFVersion>1.7</pdf:PDFVersion></rdf:Description></rdf:RDF></x:xmpmeta><?xpacket end="r"?>
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="xmp-writer"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:xmpTPg="http://ns.adobe.com/xap/1.0/t/pg/" xmlns:pdf="http://ns.adobe.com/pdf/1.3/" ><xmp:CreatorTool>Typst 0.11.0</xmp:CreatorTool><xmp:CreateDate>2024-06-25T14:10:15Z</xmp:CreateDate><xmp:ModifyDate>2024-06-25T14:10:15Z</xmp:ModifyDate><xmpTPg:NPages>1</xmpTPg:NPages><dc:format>application/pdf</dc:format><dc:language><rdf:Bag><rdf:li>en</rdf:li></rdf:Bag></dc:language><xmpMM:DocumentID>5nsOW2SnG+nAEaNXgt0fwA==</xmpMM:DocumentID><xmpMM:InstanceID>5nsOW2SnG+nAEaNXgt0fwA==</xmpMM:InstanceID><xmpMM:RenditionClass>proof</xmpMM:RenditionClass><pdf:PDFVersion>1.7</pdf:PDFVersion></rdf:Description></rdf:RDF></x:xmpmeta><?xpacket end="r"?>
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

BIN
gallery/example3.pdf Normal file

Binary file not shown.

27
gallery/example3.typ Normal file
View File

@ -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)
$

53
src/gauss.typ Normal file
View File

@ -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()