June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,6 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
int main()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include <iostream>
|
||||
#include "boost/multi_array.hpp"
|
||||
#include <boost/multi_array.hpp>
|
||||
|
||||
typedef boost::multi_array<double, 2> two_d_array_type;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,38 +1,16 @@
|
|||
julia> "Inspired by Python's `input` function."
|
||||
function input(prompt::AbstractString="")
|
||||
print(prompt)
|
||||
chomp(readline())
|
||||
end
|
||||
input (generic function with 2 methods)
|
||||
function input(prompt::AbstractString)
|
||||
print(prompt)
|
||||
return readline()
|
||||
end
|
||||
|
||||
julia> n = parse(Int, input("Upper bound for dimension 1: ")) # parse as `Int`
|
||||
Upper bound for dimension 1: 5
|
||||
5
|
||||
n = input("Upper bound for dimension 1: ") |>
|
||||
x -> parse(Int, x)
|
||||
m = input("Upper bound for dimension 2: ") |>
|
||||
x -> parse(Int, x)
|
||||
|
||||
julia> m = parse(Int, input("Upper bound for dimension 2: "))
|
||||
Upper bound for dimension 2: 5
|
||||
5
|
||||
|
||||
julia> x = rand(n, m) # create an n·m random matrix
|
||||
5x5 Array{Float64,2}:
|
||||
0.80217 0.422318 0.594049 0.45547 0.208822
|
||||
0.0533981 0.304858 0.0276755 0.797732 0.828796
|
||||
0.522506 0.563856 0.216759 0.865961 0.034306
|
||||
0.792363 0.815744 0.868697 0.42509 0.588946
|
||||
0.112034 0.539611 0.674581 0.508299 0.939373
|
||||
|
||||
julia> x[3, 3] # overloads `getindex` generic function
|
||||
0.21675944652281487
|
||||
|
||||
julia> x[3, 3] = 5 # overloads `setindex!` generic function
|
||||
5
|
||||
|
||||
julia> x::Matirx # `Matrix{T}` is an alias for `Array{T, 2}`
|
||||
5x5 Array{Float64,2}:
|
||||
0.80217 0.422318 0.594049 0.45547 0.208822
|
||||
0.0533981 0.304858 0.0276755 0.797732 0.828796
|
||||
0.522506 0.563856 5.0 0.865961 0.034306
|
||||
0.792363 0.815744 0.868697 0.42509 0.588946
|
||||
0.112034 0.539611 0.674581 0.508299 0.939373
|
||||
|
||||
julia> x = 0; gc() # Julia has no `del` command, rebind `x` and call the garbage collector
|
||||
x = rand(n, m)
|
||||
display(x)
|
||||
x[3, 3] # overloads `getindex` generic function
|
||||
x[3, 3] = 5.0 # overloads `setindex!` generic function
|
||||
x::Matrix # `Matrix{T}` is an alias for `Array{T, 2}`
|
||||
x = 0; gc() # Julia has no `del` command, rebind `x` and call the garbage collector
|
||||
|
|
|
|||
|
|
@ -1,28 +1,15 @@
|
|||
use std::env;
|
||||
|
||||
fn main() {
|
||||
let mut args = env::args().skip(1).flat_map(|num| num.parse());
|
||||
let rows = args.next().expect("Expected number of rows as first argument");
|
||||
let cols = args.next().expect("Expected number of columns as second argument");
|
||||
|
||||
assert!(rows != 0 && cols != 0);
|
||||
assert_ne!(rows, 0, "rows were zero");
|
||||
assert_ne!(cols, 0, "cols were zero");
|
||||
|
||||
// Creates a vector of vectors with all elements initialized to 0.
|
||||
let mut v = init_vec(rows, || init_vec(cols, || 0));
|
||||
let mut v = vec![vec![0; cols]; rows];
|
||||
v[0][0] = 1;
|
||||
println!("{}", v[0][0]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Returns a dynamically-allocated array of size `n`,
|
||||
// initialized with the values computed by `f`
|
||||
|
||||
fn init_vec<F,T>(n: usize, f: F) -> Vec<T>
|
||||
where F: Fn() -> T
|
||||
{
|
||||
let mut vec = Vec::with_capacity(n);
|
||||
for _ in 0..n {
|
||||
vec.push(f());
|
||||
}
|
||||
vec
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
10 PRINT "1ST DIMENSION: ";
|
||||
20 INPUT D1
|
||||
30 PRINT D1
|
||||
40 PRINT "2ND DIMENSION: ";
|
||||
50 INPUT D2
|
||||
60 PRINT D2
|
||||
70 DIM A(D1,D1)
|
||||
80 PRINT "ARRAY CREATED"
|
||||
90 LET X=1+INT (D1*RND)
|
||||
100 LET Y=1+INT (D2*RND)
|
||||
110 LET A(X,Y)=37
|
||||
120 PRINT "ITEM ";X;", ";Y;" = ";A(X,Y)
|
||||
130 CLEAR
|
||||
140 PRINT "ARRAY DESTROYED"
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
mata
|
||||
mata stata display "Number of rows?" _request(nr)
|
||||
mata stata display "Number of columns?" _request(nc)
|
||||
a=J($nr,$nc,0)
|
||||
a[1,2]=1.5
|
||||
nr = strtoreal(st_global("nr"))
|
||||
nc = strtoreal(st_global("nc"))
|
||||
a = J(nr,nc,0)
|
||||
a[1,2] = 1.5
|
||||
a
|
||||
mata drop a
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
Option Explicit
|
||||
|
||||
Sub Main_Create_Array()
|
||||
Dim NbColumns As Integer, NbRows As Integer
|
||||
|
||||
'Get two integers from the user,
|
||||
Do
|
||||
NbColumns = Application.InputBox("Enter number of columns : ", "Numeric only", 3, Type:=1)
|
||||
NbRows = Application.InputBox("Enter number of rows : ", "Numeric only", 5, Type:=1)
|
||||
Loop While NbColumns = 0 Or NbRows = 0
|
||||
'Create a two-dimensional array at runtime
|
||||
ReDim myArray(1 To NbRows, 1 To NbColumns)
|
||||
'Write some element of that array,
|
||||
myArray(LBound(myArray, 1), UBound(myArray, 2)) = "Toto"
|
||||
'and then output that element.
|
||||
MsgBox myArray(LBound(myArray, 1), UBound(myArray, 2))
|
||||
'destroy the array
|
||||
Erase myArray
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue