Spring 2025
The latest version of Julia as of this presentation is 1.11.4
julia
at the command linejulia>
print("Julia is easy!")
=
operatormy_var = 32
+, -, *, /, (, )
^
x = 2^10 + (3*5 + 1)/2 print(x)
Like R and Python, you can type commands into the console
But for anything even moderately sophisticated, you’ll probably want to create a source file
A Julia source file is a text-readable file with Julia commands in them that can be run any time
There are many advantages, not the least of which is being able to give the file to someone else to run
Also, you’ll need to turn in a source file for homework
Julia source files typically end in .jl
myboundvar::Int = 11 myboundvar = 3.5 # Will produce error struct myt a::Float64 b::String end list = [myt(2,"toad"), "Foo", myt(-3.2, "Purple")] list[1].b # Julia is 1-indexed, not 0-indexed list[3].a
int
are integersfloat
are floating point numbersx = 3 y = 4.7 x/y + 2*x - 3
z = " Hello There " length(z) print("My string was: '$z'") print( lowercase(z) ) split("This; is; a test of; split")
x = "hello" z = "world" print("$x $z")
x = [12, -3, "no", True, ['a', 'b', 'c']] x[1] x[end-1]
myVar = (1, 2, "Hello") println(myVar)
struct FooType1 a::Int64 b::Float64 end foo = FooType1(2, -6.3) foo.a foo.a = 3 # This will give an error
mutable struct FooType2 a::Int64 b::Float64 end foo = FooType2(2, -6.3) foo.a foo.a = 3 # This will not give an error
Dict2 = Dict("a" => 1, "b" => 2, "c" => 3) println("\nUntyped Dictionary = ", Dict2) Dict3 = Dict{String, Integer}("a" => 64, "c" => 20) println("\nTyped Dictionary = ", Dict3)
if x < y println("x is less than y") elseif x > y println("x is greater than y") else println("x is equal to y") end
for i in 1:10 println("Index: $i") end
Dict2 = Dict("a" => 1, "b" => 2, "c" => 3) for item in Dict3 println("Item: $item") end
cubes = [z^3 for z in 1:10] println(cubes)
# Typical Way function myfunction(arg) argsq = arg^2 return argsq end # Compact Way otherfunction(x, y) = 2*x + y # Calling functions myfunction(3) otherfunction(-2, 3)
using
and install with Pkg.add
using Pkg Pkg.add("Plots") using Plots x = 0:.1:10 z = sin.(x) plot(x,z)