array of ints
x1 = [1:10]
10-element Array{Int32,1}: 1 2 3 4 5 6 7 8 9 10
array of floats
x1 = [1.:10]
10-element Array{Float64,1}: 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
A = [ F(x,y,...) for x=rx, y=ry, ... ]
[i+j for i=1:5, j=1:5]
5x5 Array{Int32,2}: 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 5 6 7 8 9 6 7 8 9 10
x = rand(8)
8-element Array{Float64,1}: 0.604484 0.392061 0.159006 0.700496 0.016461 0.990571 0.56842 0.249582
[ 0.25*x[i-1] + 0.5*x[i] + 0.25*x[i+1] for i=2:length(x)-1 ]
6-element Array{Any,1}: 0.386903 0.352642 0.394115 0.430997 0.641506 0.594249
Pkg.add("Winston")
using Winston
plot(x1)
plot(x1, rand(10))
plot(x1, rand(10),"b-o")
x2 = rand(10,10)
10x10 Array{Float64,2}: 0.470593 0.745078 0.00507957 0.55476 … 0.849684 0.61146 0.177914 0.0176863 0.854575 0.292973 0.416571 0.89902 0.336281 0.139129 0.559851 0.610792 0.42808 0.118449 0.267995 0.935479 0.234999 0.250439 0.0527366 0.838703 0.712658 0.561449 0.378895 0.317819 0.463184 0.629851 0.417069 0.544282 0.159377 0.844525 0.299531 0.873786 0.860217 0.0142058 0.236449 … 0.789597 0.668284 0.503 0.195273 0.179327 0.450923 0.14229 0.263772 0.132346 0.31263 0.89076 0.543465 0.0208126 0.922975 0.177622 0.988187 0.931534 0.236742 0.564753 0.299484 0.0745965 0.111413 0.209411 0.293134 0.608397 0.684601 0.846688 0.675908 0.613112 0.332819 0.422293
imagesc(x2)
title("random matrix")
x = 5; y = 3;
3x + 2y
21
3x
15
ρ(T,S) = ρ0*(1-α*(T-T0)+β*(S-S0))
ρ (generic function with 1 method)
ρ0=1025
α = 2.5E-4
T0 = 20.
β = 8.E-4
S0 = 35.
35.0
ρ(10,35)
1027.5625
T = [10:15]
6-element Array{Int32,1}: 10 11 12 13 14 15
S = [35.0:0.1:35.5]
6-element Array{Float64,1}: 35.0 35.1 35.2 35.3 35.4 35.5
ρ(T,S)
6-element Array{Float64,1}: 1027.56 1027.39 1027.21 1027.04 1026.87 1026.69
plot(ρ(T,S))
st = "Hello there"
"Hello there"
string(st[1:5]," ",st[7:9])
"Hello the"
for letter in st
print(letter, "\n")
end
H e l l o t h e r e
for letter=st
print(letter, "\n")
end
H e l l o t h e r e
"1 + 2 = $(1 + 2 + S[1])"
"1 + 2 = 38.0"
"First salinity is $(S[1]) psu"
"First salinity is 35.0 psu"
"All salinities are: $S"
"All salinities are: [35.0,35.1,35.2,35.3,35.4,35.5]"
+(1,2,3,4)
10
*(1,2,3,4)
24
z = (x = 1+T[1]; y = 2*S[1]; x + y)
81.0
a ? b : c
- The expression a
, before the ?
, is a condition expression, and the ternary operation evaluates the expression b
, before the :
, if the condition a
is true
or the expression c
, after the :
, if it is false
.
1 < 2 ? print("yes") : print("no")
yes
danet(x) = (x>0) ? 1 : -1
danet (generic function with 1 method)
danet(10)
1
danet(-10)
-1
for i = 1:2, j = 3:4
println((i, j))
end
(1,3) (1,4) (2,3) (2,4)
run(`ls`|`grep U`)
Untitled0.ipynb Untitled1.ipynb