aboutsummaryrefslogtreecommitdiff
path: root/examples/FallingBall.jl
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2024-02-01 12:35:05 -0500
committersotech117 <michael_foiani@brown.edu>2024-02-01 12:35:05 -0500
commit3c7d70ebd43423220b266dab218ca6d687996d08 (patch)
treeaa4b9869ea4248858b8aee46f73da55abb22c665 /examples/FallingBall.jl
parentadb65f3f12061e6cc8919338d28e006f7fa01c2f (diff)
pull examples and complete homework 1
Diffstat (limited to 'examples/FallingBall.jl')
-rw-r--r--examples/FallingBall.jl25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/FallingBall.jl b/examples/FallingBall.jl
new file mode 100644
index 0000000..35d4b31
--- /dev/null
+++ b/examples/FallingBall.jl
@@ -0,0 +1,25 @@
+#!/Applications/Julia-1.8.app/Contents/Resources/julia/bin/julia
+
+dt = 0.01 # time step in seconds
+g = 9.8 # acceleration of gravity in m/s^2
+
+function dynamics(y::Float64, v::Float64, t::Float64)
+ for i in 1:100
+ y = y + v * dt
+ v = v - g * dt
+ t = t + dt
+ end
+
+ return y, v, t
+end
+
+y0 = 10.0 # initial position in meters
+v0 = 0.0 # initial velocity in m/s
+
+y, v, t = dynamics(y0, v0, 0.0) # evolave for 100 time steps
+
+println("\n\t Results")
+println("final time = ", t)
+println("y = ", y, " and v = ", v)
+println("exact v = ", v0 - g * t)
+println("exact y = ", y0 + v0 * t - 0.5 * g * t^2.0) \ No newline at end of file