Skip to main content
-26
Source Link
roblogic
  • 4k
  • 18
  • 23

Fortran (GFortran), 376350 376 bytes

real,allocatable,dimension(:,:)::A,B,U;read*,n
allocaten;allocate(A(n,n));B=A;U=A
read*;B=A;U=A;read*,((A(i,j),j=1,n),i=1,n)
do i=1,n;do j=1,n
if(i==j)Un;U(i,j)=1
if(i/=j)U=merge(i1,j0,i==j)=0
if(A;B(i,j)/=0)B=merge(i1.,j)=11/aA(i,j)
if(,A(i,j)==0)B(i,j)=1
enddo;enddo;enddo;enddo
do 4 l=1,99;do 4 i=1,n;do 4 j=1,n;s=U(i,j)
do;do k=1,n;m=i;if(k/=m)s=s-A(i,k)*B(k,j);enddo
B;enddo;B(m,j)=s/A(i,m)
4 continue
print'continue;print'(3(x,f9.6))',((B(i,j),j=1,n),i=1,n)
end

Try it online!Try it Online!   376 bytes

Adapted from  http://www.uprh.edu/rbaretti/MatrixInv17mar2014.htmhere. Saved 26 bytes using merge instead of if.

Fortran (GFortran), 376 bytes

real,allocatable,dimension(:,:)::A,B,U;read*,n
allocate(A(n,n));B=A;U=A
read*,((A(i,j),j=1,n),i=1,n)
do i=1,n;do j=1,n
if(i==j)U(i,j)=1
if(i/=j)U(i,j)=0
if(A(i,j)/=0)B(i,j)=1/a(i,j)
if(A(i,j)==0)B(i,j)=1
enddo;enddo
do 4 l=1,99;do 4 i=1,n;do 4 j=1,n;s=U(i,j)
do k=1,n;m=i;if(k/=m)s=s-A(i,k)*B(k,j);enddo
B(m,j)=s/A(i,m)
4 continue
print'(3(x,f9.6))',((B(i,j),j=1,n),i=1,n)
end

Try it online!

Adapted from  http://www.uprh.edu/rbaretti/MatrixInv17mar2014.htm

Fortran (GFortran), 350 376 bytes

real,allocatable,dimension(:,:)::A,B,U;read*,n;allocate(A(n,n));B=A;U=A;read*,((A(i,j),j=1,n),i=1,n)
do i=1,n;do j=1,n;U(i,j)=merge(1,0,i==j);B(i,j)=merge(1.,1/A(i,j),A(i,j)==0);enddo;enddo
do 4 l=1,99;do 4 i=1,n;do 4 j=1,n;s=U(i,j);do k=1,n;m=i;if(k/=m)s=s-A(i,k)*B(k,j);enddo;B(m,j)=s/A(i,m)
4 continue;print'(3(x,f9.6))',((B(i,j),j=1,n),i=1,n)
end

Try it Online!   376 bytes

Adapted from here. Saved 26 bytes using merge instead of if.

deleted 125 characters in body
Source Link
roblogic
  • 4k
  • 18
  • 23

Fortran (GFortran), 410376 bytes

real,allocatable,dimension(:,:)::A,B,U;read*,n
allocate(A(n,n));allocate(B(n,n));allocate(U(n,n));B=A;U=A
do i=1,n;read*read*,((A(i,j),j=1,n);enddo,i=1,n)
do i=1,n;do j=1,n
if(i==j)U(i,j)=1
if(i/=j)U(i,j)=0
if(aA(i,j)/=0)B(i,j)=1/a(i,j)
if(aA(i,j)==0)B(i,j)=1
enddo;enddo
do 4 l=1,99;do 4 i=1,n;do 4 j=1,n;s=U(i,j)
do k=1,n;m=i;if(k/=m)s=s-A(i,k)*B(k,j);enddo
B(m,j)=s/A(i,m);enddo;enddo;enddo
4 continue
print'(3(x,f9.6))',((B(i,j),j=1,n),i=1,n)
end

Try it online!Try it online!

Coulda saved 50 bytes if TIO allowed the flags -std=gnu -frealloc-lhs, then I could delete line 2. Adapted from http://www.uprh.edu/rbaretti/MatrixInv17mar2014.htm

Fortran (GFortran), 410 bytes

real,allocatable,dimension(:,:)::A,B,U;read*,n
allocate(A(n,n));allocate(B(n,n));allocate(U(n,n))
do i=1,n;read*,(A(i,j),j=1,n);enddo
do i=1,n;do j=1,n
if(i==j)U(i,j)=1
if(i/=j)U(i,j)=0
if(a(i,j)/=0)B(i,j)=1/a(i,j)
if(a(i,j)==0)B(i,j)=1
enddo;enddo
do l=1,99;do i=1,n;do j=1,n;s=U(i,j)
do k=1,n;m=i;if(k/=m)s=s-A(i,k)*B(k,j);enddo
B(m,j)=s/A(i,m);enddo;enddo;enddo
print'(3(x,f9.6))',((B(i,j),j=1,n),i=1,n)
end

Try it online!

Coulda saved 50 bytes if TIO allowed the flags -std=gnu -frealloc-lhs, then I could delete line 2. Adapted from http://www.uprh.edu/rbaretti/MatrixInv17mar2014.htm

Fortran (GFortran), 376 bytes

real,allocatable,dimension(:,:)::A,B,U;read*,n
allocate(A(n,n));B=A;U=A
read*,((A(i,j),j=1,n),i=1,n)
do i=1,n;do j=1,n
if(i==j)U(i,j)=1
if(i/=j)U(i,j)=0
if(A(i,j)/=0)B(i,j)=1/a(i,j)
if(A(i,j)==0)B(i,j)=1
enddo;enddo
do 4 l=1,99;do 4 i=1,n;do 4 j=1,n;s=U(i,j)
do k=1,n;m=i;if(k/=m)s=s-A(i,k)*B(k,j);enddo
B(m,j)=s/A(i,m)
4 continue
print'(3(x,f9.6))',((B(i,j),j=1,n),i=1,n)
end

Try it online!

Adapted from http://www.uprh.edu/rbaretti/MatrixInv17mar2014.htm

Source Link
roblogic
  • 4k
  • 18
  • 23

Fortran (GFortran), 410 bytes

real,allocatable,dimension(:,:)::A,B,U;read*,n
allocate(A(n,n));allocate(B(n,n));allocate(U(n,n))
do i=1,n;read*,(A(i,j),j=1,n);enddo
do i=1,n;do j=1,n
if(i==j)U(i,j)=1
if(i/=j)U(i,j)=0
if(a(i,j)/=0)B(i,j)=1/a(i,j)
if(a(i,j)==0)B(i,j)=1
enddo;enddo
do l=1,99;do i=1,n;do j=1,n;s=U(i,j)
do k=1,n;m=i;if(k/=m)s=s-A(i,k)*B(k,j);enddo
B(m,j)=s/A(i,m);enddo;enddo;enddo
print'(3(x,f9.6))',((B(i,j),j=1,n),i=1,n)
end

Try it online!

Coulda saved 50 bytes if TIO allowed the flags -std=gnu -frealloc-lhs, then I could delete line 2. Adapted from http://www.uprh.edu/rbaretti/MatrixInv17mar2014.htm