[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 1.21 MB, 4032x3024, 1597398748820.jpg [View same] [iqdb] [saucenao] [google]
12650438 No.12650438 [Reply] [Original]

Sup, im building a matrix library in rust and trying to learn more about how to find the inverse of a matrix. Been googling and searching for information but can't really find anything useful, like at all. I found Gaussian elimination which sounded sounded about right but the method seems too arbirtary and hard to code due it being up to the person solving the person deciding whether to swap a row, multiply it, add it or whatever. Is there a strict set of guidlines for finding the inverse of a matrix? Please let me know what or where to look for it, thanks!

>> No.12650442

>he uses Rust
>he has to say he uses Rust
Insufferable smartass.

>> No.12650446

>>12650442
Im clearly not smart im posting on fucking 4chan and cant even find the inverse of a matrix

>> No.12650450

>>12650442
smartass? more like dumbass.
OP, word of widsom: outside a small number of cases, you let others write your linear algebra libraries

>> No.12650451

>>12650442
>Insufferable smartass
Btw, were on sci, it's legit only these kinds of people here wtf

>> No.12650454

also, gauss-jordon elimination is the only method you will understand. more advanced methods will be beyond you

>> No.12650458

>>12650450
>you let others write your linear algebra libraries
>He cant even print hello world
brainlet

>> No.12650464

>>12650454
Yeah i guess but am i wrong in my assumption about it being very arbitrary?

>> No.12650474

This board is so dead baka

>> No.12650476
File: 99 KB, 397x383, 1610858284645.jpg [View same] [iqdb] [saucenao] [google]
12650476

>>12650464
it would be good coding and math practice for you to work out the algorithm and code it up. it's not hard.

>> No.12650480

>>12650476
True true my guy, ima keep at it desu

>> No.12650632

>>12650438
Create an extended matrix with the identity matrix, then reduce the original matrix to the identity. The identity will then be the inverse. I don't know how to code

>> No.12650670

>>12650438
Do you "really" want to find an inverse? Most of the time you want that because you want to solve matrix equation but there are far better methods to do that. Read https://www.johndcook.com/blog/2010/01/19/dont-invert-that-matrix/

>> No.12650708

>>12650438
What sizes? And why are you building it? You may not need to do something that general

>> No.12650747

>>12650438
>in rust
Fuck off back to /g/
>but can't really find anything useful
https://4chan-science.fandom.com/wiki/Computer_Science_and_Engineering#Numerical_Linear_Algebra

>> No.12650756

>>12650438

Don't you know how to calcualte it by hand? Just implement that algorithm step by step. It's really not that difficult. I'm a pajeet btw and i did stuff like that in 6th or 7th grade.

>> No.12650771

>>12650438
Gaussian elimination is not arbitrary. In fact, it's the most obvious and exhaustive algorithm. It's the "brute force" method.
There are tons of dexompostiona, like low triangular and other stuff that allowsnyou to do tricks. But I wouldn't program my own linear algebra library, I have done it for a computational physics intro course, but it was just as an exercise.

>> No.12651498

>>12650670
in practice i doubt anyone computes an explicit inverse to anything larger than 4x4 linear systems. typically you use regularized iterative methods like conjugate gradient or gmres

>> No.12652876

>>12650438
How is it arbitrary?
I remember we did it and it was pretty straightforward. Gimme a sec.

>> No.12652900

>>12650438
Ok, well I can't find my notes but here you go

https://www.codesansar.com/numerical-methods/matrix-inverse-using-gauss-jordan-method-pseudocode.htm

>> No.12652901
File: 195 KB, 1024x1024, trannyder.jpg [View same] [iqdb] [saucenao] [google]
12652901

>>12650438
>I found Gaussian elimination which sounded sounded about right but the method seems too arbirtary and hard to code
I thought all of you mentally ill pedoTrannies were just as good as the single white male autists (that are probably facist nazi /pol/ retards) right ?
Fucking end yourself by getting 41% closer to 42% you fucking retard.

>> No.12652929

the virgin matrix inverse
vs
the chad "apply the matrix over and over again until i get the answer"

>> No.12652952

>>12650438
Use python instead

>> No.12652960

Feel free to use. I don't give all and its moonspeak so you can learn while changing it t your languages (talking+programming).



public Matriisi inverssi() {
Matriisi inverssi=new Matriisi(this.sarakkeet,this.rivit);
inverssi=this.kofaktori().transpoosi();
for(int i=0;i<this.rivit;i++) {
for(int j=0;j<this.sarakkeet;j++) {
inverssi.matriisi[j]/=this.determinantti();
}
}

return inverssi;
}


public Matriisi kofaktori() {

Matriisi kofaktori=new Matriisi(this.sarakkeet,this.rivit);
Matriisi alimatriisi=new Matriisi(this.sarakkeet-1,this.rivit-1);


for(int i=0;i<this.rivit;i++) {
for(int j=0;j<this.sarakkeet;j++) {
for(int k=0;k<alimatriisi.rivit;k++) {
for(int l=0;l<alimatriisi.rivit;l++) {

if(k<i&&l<j) {alimatriisi.matriisi[k][l]=this.matriisi[k][l];}
else if(k<i&&l>=j) {alimatriisi.matriisi[k][l]=this.matriisi[k][l+1];}
else if(k>=i&&l<j) {alimatriisi.matriisi[k][l]=this.matriisi[k+1][l];}
else {alimatriisi.matriisi[k][l]=this.matriisi[k+1][l+1];}
}
}
kofaktori.matriisi[j]=Math.pow(-1, i+j)*alimatriisi.determinantti();
}
}
return kofaktori;
}
public double determinantti() {
if(this.rivit==1) {return matriisi[0][0];}
else {
double det=0;
Matriisi alimatriisi=new Matriisi(this.rivit-1,this.rivit-1);

for(int i=0;i<this.rivit;i++) {

for(int k=0;k<alimatriisi.rivit;k++) {
for(int l=0;l<alimatriisi.rivit;l++) {
if(l<i) {
alimatriisi.matriisi[k][l]=this.matriisi[k+1][l];
}
else {
alimatriisi.matriisi[k][l]=this.matriisi[k+1][l+1];
}
}
}
det+=Math.pow(-1, i)*this.matriisi[0]*alimatriisi.determinantti();
}
return det;
}
}

>> No.12653017

>>12652960
the computational complexity of this code is atrocious and does not scale at all

>> No.12653040 [DELETED] 

>>12652960
>public
Kill yourself faggot

>> No.12653064

The Virgin user of direct solvers vs. The Chad profesional of iterative methods

>> No.12653111

>>12653064
They hated him because he spoke the truth

>> No.12653113

>>12650438
I don't want to make anyone sad right now, but that cat is long dead.

>> No.12653127

>>12650442
People like you should be hung.

>> No.12653212

>>12650438
>hard to code due it being up to the person solving the person deciding whether to swap a row, multiply it, add it or whatever.
you mean you?

>> No.12653227
File: 66 KB, 919x665, 1610401357002.jpg [View same] [iqdb] [saucenao] [google]
12653227

>>12653064
Jacobi is king
Imagine using some weird sequential algorithm, meanwhile chads just program the jacobi algorithm on their GPU

>> No.12653229

>>12653017
and yets its the onlycode in this stupid thread

It's just for scientific curiosity: inverse is adjoint per determinant. Use existent packages and matrix libraries if you want speed.

>> No.12653261

This is Rust's matrix lib if you don't want to learn linalg.

https://nalgebra.org/

>> No.12653719

>>12650438
Like, a matrix where neo is a sheeplez? Or where humans write a program to simulate machines? You at least have to define inversion if you want us to help

>> No.12653792

>>12650438
Transpose the cofactor matrix and divide by the determinant
https://www.mathsisfun.com/algebra/matrix-inverse-minors-cofactors-adjugate.html

>> No.12653904

>>12650438
>been searching for info
lie - even a first page returns many good results like this one: https://en.wikipedia.org/wiki/Invertible_matrix#Methods_of_matrix_inversion

>> No.12654077

>>12653229
>inverse is adjoint per determinant
theoretically useful, almost practically useless

>> No.12654272

Just solved using a method of finding out the determinant aswell as the adjunct of the matrix. Feels good man

>> No.12654291

>>12654272
do an experiment: graph the compute time as a function of matrix size N at post the result

>> No.12654298

>>12650438
Rust is the Linux of coding

>> No.12654301

>>12653127
Damn right I am baby
Just ask your mom she saw it last night

>> No.12654319

>>12654298
you will never be a woman

>> No.12654381

>>12654291
Lol that would be too embaressing

>> No.12654429

>>12650438
Here's a simple Python implementation of Jacobi method

mat = [[1,1,0],
[0,1,0],
[0,0,2]]

y = [1,2.5,5]

def jacobi(A, b, max_iters=100):
dim = len(A) # Matrix dimension
x = [0 for i in range(dim)]

for _ in range(max_iters):
new_x = []
for i in range(dim):
sig = sum([A[i][j]*x[j] for j in range(dim) if i != j])
new_x.append((b[i]-sig)/A[i][i])

if max([abs(x[k]-new_x[k]) for k in range(len(x))]) < 1e-6:
return new_x
else:
x = new_x

print("Final result:", jacobi(mat, y))

>> No.12654437

>>12654429
Ah shit, 4chan removed indentation. Fuck

>> No.12654443

>>12654437
ha, stupid python

>> No.12654560

>>12654319
California's housing problem is solved
They all live in your head now, rent free

>> No.12654652

>>12650446
just use >>12650454, am I the retarded one?
>>12650450
also this