Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -1,4 +1,4 @@
.=/¨3 3
.=3
1 0 0
0 1 0
0 0 1

View file

@ -1,4 +1,4 @@
ID{.=/¨ }
ID{.=}
ID 5
1 0 0 0 0
0 1 0 0 0

View file

@ -0,0 +1,15 @@
100 INPUT "MATRIX SIZE:"; SIZE%
110 GOSUB 200"IDENTITYMATRIX
120 FOR R = 0 TO SIZE%
130 FOR C = 0 TO SIZE%
140 LET S$ = CHR$(13)
150 IF C < SIZE% THEN S$ = " "
160 PRINT IM(R, C) S$; : NEXT C, R
170 END
200 REMIDENTITYMATRIX SIZE%
210 LET SIZE% = SIZE% - 1
220 DIM IM(SIZE%, SIZE%)
230 FOR I = 0 TO SIZE%
240 LET IM(I, I) = 1 : NEXT I
250 RETURN :IM

View file

@ -0,0 +1,25 @@
program IdentityMatrix;
// Modified from the Pascal version
{$APPTYPE CONSOLE}
var
matrix: array of array of integer;
n, i, j: integer;
begin
write('Size of matrix: ');
readln(n);
setlength(matrix, n, n);
for i := 0 to n - 1 do
matrix[i,i] := 1;
for i := 0 to n - 1 do
begin
for j := 0 to n - 1 do
write (matrix[i,j], ' ');
writeln;
end;
end.

View file

@ -0,0 +1,9 @@
defmodule Matrix do
def identity(n) do
Enum.map(0..n-1, fn i ->
for j <- 0..n-1, do: (if i==j, do: 1, else: 0)
end)
end
end
IO.inspect Matrix.identity(5)

View file

@ -0,0 +1,9 @@
Program Identity
Integer N
Parameter (N = 666)
Real A(N,N)
Integer i,j
ForAll(i = 1:N, j = 1:N) A(i,j) = (i/j)*(j/i)
END

View file

@ -1,18 +1,19 @@
package main
import "fmt"
import (
"fmt"
func main() {
fmt.Println(I(3))
}
"github.com/gonum/matrix/mat64"
)
func I(n int) [][]float64 {
m := make([][]float64, n)
a := make([]float64, n*n)
func eye(n int) *mat64.Dense {
m := mat64.NewDense(n, n, nil)
for i := 0; i < n; i++ {
a[i] = 1
m[i] = a[:n]
a = a[n:]
m.Set(i, i, 1)
}
return m
}
func main() {
fmt.Println(mat64.Formatted(eye(3)))
}

View file

@ -1,18 +1,11 @@
package main
import "fmt"
import (
"fmt"
type matrix []float64
mat "github.com/skelterjohn/go.matrix"
)
func main() {
fmt.Println(I(3))
}
func I(n int) matrix {
m := make(matrix, n*n)
n++
for i := 0; i < len(m); i += n {
m[i] = 1
}
return m
fmt.Println(mat.Eye(3))
}

View file

@ -1,11 +1,17 @@
package main
import (
"fmt"
mat "github.com/skelterjohn/go.matrix"
)
import "fmt"
func main() {
fmt.Println(mat.Eye(3))
fmt.Println(I(3))
}
func I(n int) [][]float64 {
m := make([][]float64, n)
for i := 0; i < n; i++ {
a := make([]float64, n)
a[i] = 1
m[i] = a
}
return m
}

View file

@ -0,0 +1,18 @@
package main
import "fmt"
func main() {
fmt.Println(I(3))
}
func I(n int) [][]float64 {
m := make([][]float64, n)
a := make([]float64, n*n)
for i := 0; i < n; i++ {
a[i] = 1
m[i] = a[:n]
a = a[n:]
}
return m
}

View file

@ -0,0 +1,34 @@
package main
import "fmt"
type matrix []float64
func main() {
n := 3
m := I(n)
// dump flat represenation
fmt.Println(m)
// function x turns a row and column into an index into the
// flat representation.
x := func(r, c int) int { return r*n + c }
// access m by row and column.
for r := 0; r < n; r++ {
for c := 0; c < n; c++ {
fmt.Print(m[x(r, c)], " ")
}
fmt.Println()
}
}
func I(n int) matrix {
m := make(matrix, n*n)
// a fast way to initialize the flat representation
n++
for i := 0; i < len(m); i += n {
m[i] = 1
}
return m
}

View file

@ -1,6 +1,6 @@
sub identity-matrix($n) {
my @id;
for ^$n X ^$n -> $i, $j {
for flat ^$n X ^$n -> $i, $j {
@id[$i][$j] = +($i == $j);
}
@id;

View file

@ -1,3 +1,3 @@
sub identity-matrix($n) {
[1, 0 xx $n-1], *.rotate(-1).item ... *[*-1] == 1
([1, |(0 xx $n-1)].item, *.rotate(-1).item ... *)[^$n]
}

View file

@ -0,0 +1,21 @@
function id($n) {
if($n -gt 0) {
$array = @(1..$n | foreach{ @(0) })
0..($n-1) | foreach{
$i = $_
$array[$i] = @(switch(0..($n-1)){
$i {1}
default {0}
})
}
$array
} else { @() }
}
function show($a) {
if($a.Count -gt 0) {
$n = $a.Count - 1
0..$n | foreach{ "$($a[$_][0..$n])" }
}
}
$array = id 4
show $array

View file

@ -0,0 +1,2 @@
$array[0][0]
$array[0][1]

View file

@ -0,0 +1,29 @@
build_matrix(7)
Sub build_matrix(n)
Dim matrix()
ReDim matrix(n-1,n-1)
i = 0
'populate the matrix
For row = 0 To n-1
For col = 0 To n-1
If col = i Then
matrix(row,col) = 1
Else
matrix(row,col) = 0
End If
Next
i = i + 1
Next
'display the matrix
For row = 0 To n-1
For col = 0 To n-1
If col < n-1 Then
WScript.StdOut.Write matrix(row,col) & " "
Else
WScript.StdOut.Write matrix(row,col)
End If
Next
WScript.StdOut.WriteLine
Next
End Sub