Introduction to Julia
James Fulton
Climate informatics researcher
# Store the number 3 in the variable x x = 3
# Print the variable println(x)
3
double_x = 2*x
println(double_x)
6
# Distance run in meters distance = 5000 # Time taken in minutes time = 32.3
# Convert distance to miles and time to hours distance_miles = distance/1609
time_hours = time/60
# Print speed in miles per hour println(distance_miles/time_hours)
5.772483341575157
# Distance in meters distance = 5000 # Time taken in minutes
time = 30.1
# Convert distance to miles and time to hours distance_miles = distance/1609 time_hours = time/60 # Print speed in miles per hour println(distance_miles/time_hours)
6.194392423019188
Variable names in previous example:
distance
, time
, distance_miles
, time_hours
[a-z]
or [A-Z]
_
time_hours
$\rightarrow$ timehours
x_times_2
is valid2_times_x
is not validOperator | Operation | Example | Result |
---|---|---|---|
+ |
Add | 1+2 |
3 |
- |
Subtract | 4-2 |
2 |
* |
Multiply | 5*3 |
15 |
/ |
Divide | 20/4 |
5 |
^ |
Power | 2^3 |
8 |
2^3
is the same as 2*2*2
speed = (distance/1609)/(time/60)
println(speed)
5.772483341575157
speed = distance/1609/time/60
println(speed)
0.0016034675948819882
Introduction to Julia