In [1]:
using PyCall
In [2]:
@pyimport matplotlib.pyplot as plt
x = linspace(0,2*pi,1000); y = sin(3*x + 4*cos(2*x));
plt.plot(x, y, color="red", linewidth=2.0, linestyle="--")
plt.show()
In [3]:
x
Out[3]:
In [4]:
@pyimport scipy.optimize as so
opt = so.newton(x -> cos(x) - x, 1)
Out[4]:
In [5]:
opt
Out[5]:
In [6]:
x[0]
In [7]:
mat = [1 2 3; 4 5 6; 7 8 9]
Out[7]:
In [8]:
eig(mat)
Out[8]:
In [9]:
mat1 = 1:9
reshape(mat1,3,3)
Out[9]:
In [10]:
size = 1000
mat = rand(size,size);
In [11]:
blas_set_num_threads(1)
t1 = @elapsed eig(mat);
blas_set_num_threads(4)
t4 = @elapsed eig(mat);
In [12]:
t1/t4
Out[12]:
In [13]:
function count_heads(n)
c::Int = 0
for i=1:n
c += rand(Bool)
end
c
end
t = @elapsed (a = @spawn count_heads(100000000);b = @spawn count_heads(100000000);)
fetch(a)+fetch(b)
t
Out[13]:
In [14]:
t = @elapsed nheads = @parallel (+) for i=1:200000000
Int(rand(Bool))
end
t
Out[14]:
In [15]:
nheads=0
t = @elapsed for i=1:200000000
nheads += Int(rand(Bool))
end
t
Out[15]:
In [16]:
macro sayhello()
return :( println("Hello!") )
end
In [17]:
@sayhello
In [ ]: