In [1]:
println("hi")
In [3]:
f(x) = 10 * x + sin(x)
Out[3]:
In [4]:
f(1)
Out[4]:
Get the Greeks by typing \pi
followed by a tab key
In [6]:
π
Out[6]:
In [9]:
# this is a comment
In [10]:
area(r) = π * r^2
Out[10]:
In [11]:
area(3)
Out[11]:
Use Pkg.add("Gadfly")
to add a package
In [14]:
using Gadfly
In [16]:
g(x) = sin(x)
Out[16]:
In [17]:
plot(g, 0, 10)
Out[17]:
In [28]:
x = abs(3*(4/3-1)-1)
Out[28]:
In [24]:
eps()
Out[24]:
In [26]:
typeof(ans)
Out[26]:
In [27]:
typeof(eps())
Out[27]:
In [29]:
eps() == x
Out[29]:
In [30]:
4/3-1
Out[30]:
In [32]:
1 + eps() == 1
Out[32]:
In [35]:
eps() / 2 + 1 == 1
Out[35]:
eps()
is the machine epsilonsys.float_info.epsilon
in python
In [37]:
x = 1.0
y = x / 3.0
Out[37]:
In [38]:
x == y * 3.0
Out[38]:
In [43]:
1//3
Out[43]:
In [45]:
1//3 + 2//3 == 1
Out[45]:
In [47]:
1//3 + 3 // 4
Out[47]:
In [48]:
f(x) = (exp(x) - 1) / x - 1
Out[48]:
In [62]:
plot(f, -2, 2)
Out[62]:
In [65]:
f(0.1)
Out[65]:
In [66]:
f(-0.1)
Out[66]:
In [68]:
f(-0.001)
Out[68]:
In [69]:
f(0)
Out[69]:
In [70]:
f(x) = exp(-1/x^2)
Out[70]:
In [72]:
plot(f, -1, 1)
Out[72]:
In [73]:
a = (1,2,3)
Out[73]:
In [76]:
typeof(a)
Out[76]:
In [77]:
a = [1, 2, 3]
Out[77]:
In [78]:
typeof(a)
Out[78]:
In [81]:
dot(a, [1,2,3])
Out[81]:
In [84]:
f(x) = x^3 + x^2 - 8*x + 4
Out[84]:
In [85]:
plot(f, -4, 4)
Out[85]:
In [87]:
plot(f, -2, 2)
Out[87]:
In [86]:
plot(f, -1, 1)
Out[86]:
In [1]:
function f(x)
y = x + 1
return y + 2
end
Out[1]:
In [2]:
f(3)
Out[2]:
In [3]:
x -> x * 2
Out[3]:
In [4]:
function(x) x + 2 end
Out[4]:
In [5]:
map(x -> x * 2, [1, 2, 3])
Out[5]:
In [7]:
maximum([1,2,3])
Out[7]:
In [8]:
function f(array)
max = maximum(array)
scaled = map(x -> (x / max) * (x / max), array)
return sqrt(reduce(+, scaled))
end
Out[8]:
In [9]:
f([1,2,3])
Out[9]:
In [10]:
f([1,2])
Out[10]:
In [11]:
reduce(*, [1,2,3])
Out[11]:
In [13]:
a = 1
b = eps() / 2
((a + b) - a) - b
Out[13]: