summaryrefslogtreecommitdiffstats
path: root/assignments/hw02/euler.jl
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2014-05-21 00:59:10 -0400
committerbnewbold <bnewbold@robocracy.org>2014-05-21 00:59:10 -0400
commit392a611d547287920c46edbdaa8c2025596c8edb (patch)
tree3deca9e73fd2866739f5c8e53adb21b4700c6ad8 /assignments/hw02/euler.jl
parente6041a7844841e6bf138f814a705c21d6fb66c2e (diff)
downloaddmmsb2014-392a611d547287920c46edbdaa8c2025596c8edb.tar.gz
dmmsb2014-392a611d547287920c46edbdaa8c2025596c8edb.zip
hw02 first attempt
Diffstat (limited to 'assignments/hw02/euler.jl')
-rw-r--r--assignments/hw02/euler.jl29
1 files changed, 29 insertions, 0 deletions
diff --git a/assignments/hw02/euler.jl b/assignments/hw02/euler.jl
new file mode 100644
index 0000000..a9513bf
--- /dev/null
+++ b/assignments/hw02/euler.jl
@@ -0,0 +1,29 @@
+
+# Use Euler's method to integrate simple one variable ODE
+# Use program as template for more interesting models
+
+# Note: produces slightly different output compared with
+# example shown in class. Different values of b, dt, tlast
+
+using Winston
+
+a = 20
+b = 0.5
+c = 5
+
+dt = 0.2
+tlast = 20
+
+iterations = integer(round(tlast/dt))
+xall = zeros(Float64, (iterations, 1))
+
+x = c
+for i = 1:iterations
+ xall[i] = x
+ dxdt = a - b*x
+ x = x + dxdt*dt
+end
+
+time = dt*(0:iterations-1)'
+figure
+plot(time,xall)