In [1]:
# This is a comment
# I want to be able to use the Plots module
using Plots
In [2]:
# Julia is typed
1+1
Out[2]:
2
In [3]:
1.0 + 1.0
Out[3]:
2.0
In [4]:
@show typeof(1+1)
typeof(1 + 1) = Int64
Out[4]:
Int64
In [5]:
@show typeof(1.0 + 1.0)
typeof(1.0 + 1.0) = Float64
Out[5]:
Float64
In [7]:
# Having types can be helpful!
# Matlab really has types too, it's just many things default to Float64
setprecision(BigFloat, 512)
BigFloat(1.)+BigFloat(1.)
Out[7]:
2.0
In [8]:
# BigFloat's can be confusing
@show BigFloat(2.1)          # represents 2.1 as a Float64, then convert to BigFloat
@show parse(BigFloat,"2.1")  # parse the string "2.1" as a BigFloat
@show big"2.1"               # shorthand for parse(BigFloat)
BigFloat(2.1) = 2.100000000000000088817841970012523233890533447265625
parse(BigFloat, "2.1") = 2.09999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999988
big"2.1" = 2.09999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999988
Out[8]:
2.09999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999988
In [11]:
f(x) = x^2+2x+1
f(5)
Out[11]:
36
In [12]:
f(6)
Out[12]:
49
In [14]:
xx = range(-1,1,length=100)
plot(xx, f.(xx))
Out[14]:
In [16]:
f(xx)
MethodError: no method matching ^(::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Int64)
Closest candidates are:
  ^(!Matched::BigInt, ::Integer) at gmp.jl:602
  ^(!Matched::Regex, ::Integer) at regex.jl:729
  ^(!Matched::Missing, ::Integer) at missing.jl:155
  ...

Stacktrace:
 [1] macro expansion at ./none:0 [inlined]
 [2] literal_pow at ./none:0 [inlined]
 [3] f(::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}) at ./In[11]:1
 [4] top-level scope at In[16]:1
 [5] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091