June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -3,11 +3,11 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gonum/matrix/mat64"
|
||||
"gonum.org/v1/gonum/mat"
|
||||
)
|
||||
|
||||
func eye(n int) *mat64.Dense {
|
||||
m := mat64.NewDense(n, n, nil)
|
||||
func eye(n int) *mat.Dense {
|
||||
m := mat.NewDense(n, n, nil)
|
||||
for i := 0; i < n; i++ {
|
||||
m.Set(i, i, 1)
|
||||
}
|
||||
|
|
@ -15,5 +15,5 @@ func eye(n int) *mat64.Dense {
|
|||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(mat64.Formatted(eye(3)))
|
||||
fmt.Println(mat.Formatted(eye(3)))
|
||||
}
|
||||
|
|
|
|||
41
Task/Identity-matrix/Rust/identity-matrix.rust
Normal file
41
Task/Identity-matrix/Rust/identity-matrix.rust
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
extern crate num;
|
||||
struct Matrix<T> {
|
||||
data: Vec<T>,
|
||||
size: usize,
|
||||
}
|
||||
|
||||
impl<T> Matrix<T>
|
||||
where
|
||||
T: num::Num + Clone + Copy,
|
||||
{
|
||||
fn new(size: usize) -> Self {
|
||||
Self {
|
||||
data: vec![T::zero(); size * size],
|
||||
size: size,
|
||||
}
|
||||
}
|
||||
fn get(&mut self, x: usize, y: usize) -> T {
|
||||
self.data[x + self.size * y]
|
||||
}
|
||||
fn identity(&mut self) {
|
||||
for (i, item) in self.data.iter_mut().enumerate() {
|
||||
*item = if i % (self.size + 1) == 0 {
|
||||
T::one()
|
||||
} else {
|
||||
T::zero()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let size = std::env::args().nth(1).unwrap().parse().unwrap();
|
||||
let mut matrix = Matrix::<i32>::new(size);
|
||||
matrix.identity();
|
||||
for y in 0..size {
|
||||
for x in 0..size {
|
||||
print!("{} ", matrix.get(x, y));
|
||||
}
|
||||
println!();
|
||||
}
|
||||
}
|
||||
8
Task/Identity-matrix/Stata/identity-matrix-1.stata
Normal file
8
Task/Identity-matrix/Stata/identity-matrix-1.stata
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
. mat a = I(3)
|
||||
. mat list a
|
||||
|
||||
symmetric a[3,3]
|
||||
c1 c2 c3
|
||||
r1 1
|
||||
r2 0 1
|
||||
r3 0 0 1
|
||||
8
Task/Identity-matrix/Stata/identity-matrix-2.stata
Normal file
8
Task/Identity-matrix/Stata/identity-matrix-2.stata
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
: I(3)
|
||||
[symmetric]
|
||||
1 2 3
|
||||
+-------------+
|
||||
1 | 1 |
|
||||
2 | 0 1 |
|
||||
3 | 0 0 1 |
|
||||
+-------------+
|
||||
Loading…
Add table
Add a link
Reference in a new issue