summaryrefslogtreecommitdiffstats
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
parente6041a7844841e6bf138f814a705c21d6fb66c2e (diff)
downloaddmmsb2014-392a611d547287920c46edbdaa8c2025596c8edb.zip
dmmsb2014-392a611d547287920c46edbdaa8c2025596c8edb.tar.gz
hw02 first attempt
-rw-r--r--assignments/hw02/answers.txt18
-rw-r--r--assignments/hw02/euler.jl29
-rw-r--r--assignments/hw02/euler.m26
-rw-r--r--assignments/hw02/euler_mod.jl143
-rw-r--r--assignments/hw02/quiz2.pdfbin0 -> 531615 bytes
5 files changed, 216 insertions, 0 deletions
diff --git a/assignments/hw02/answers.txt b/assignments/hw02/answers.txt
new file mode 100644
index 0000000..f7a287e
--- /dev/null
+++ b/assignments/hw02/answers.txt
@@ -0,0 +1,18 @@
+
+Q1: The concentrations of ATP and Glucose never reach a stable steady-state.
+Q2: 20.98, 18.66
+Q3: no, no, yes, no
+Q4: second choice is the fastest
+Q5: first is fastest
+Q6: no, no, yes, no
+Q7: the last is the damped one (spiral)
+Q8: true, false, false, false ("When is higher than 1 no sustained
+ oscillations will be observed.")
+Q9: false, false (decaying), true, false
+Q10: true, false, false, false
+Q11: false, false, true, false
+
+
+got 2x wrong: Q7 (forgot to select?)
+ Q4 (typo? forgot to select?)
+
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)
diff --git a/assignments/hw02/euler.m b/assignments/hw02/euler.m
new file mode 100644
index 0000000..1773e6c
--- /dev/null
+++ b/assignments/hw02/euler.m
@@ -0,0 +1,26 @@
+% % 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
+
+a = 20 ;
+b = 0.5 ;
+c = 5 ;
+
+dt = 0.2 ;
+tlast = 20 ; % s
+
+iterations = round(tlast/dt) ;
+xall = zeros(iterations,1) ;
+
+x = c ;
+for i = 1:iterations
+ xall(i) = x ;
+ dxdt = a - b*x ;
+ x = x + dxdt*dt ;
+end % of this time step
+
+time = dt*(0:iterations-1)' ;
+figure
+plot(time,xall)
diff --git a/assignments/hw02/euler_mod.jl b/assignments/hw02/euler_mod.jl
new file mode 100644
index 0000000..65446d1
--- /dev/null
+++ b/assignments/hw02/euler_mod.jl
@@ -0,0 +1,143 @@
+
+using Winston
+
+function doPlot(V_in, k_l, k_p, K_m)
+
+ dt = 0.2
+ tlast = 1000
+
+ iterations = integer(round(tlast/dt))
+ ATPall = zeros(Float64, (iterations, 1))
+ Gall = zeros(Float64, (iterations, 1))
+
+ ATP = 4
+ G = 3
+ for i = 1:iterations
+ ATPall[i] = ATP
+ Gall[i] = G
+
+ dATPdt = 2 * k_l * G * ATP - (k_p * ATP) / (ATP + K_m)
+ dGdt = V_in - k_l * G * ATP
+
+ ATP = ATP + dATPdt * dt
+ G = G + dGdt * dt
+ end
+
+ tall = dt*(0:iterations-1)'
+ figure()
+ hold(true)
+ plot(tall, ATPall, color="red")
+ plot(tall, Gall, color="blue")
+ hold(false)
+ xlabel("Time")
+
+ println("max(G) = ", maximum(Gall))
+ println("max(ATP) = ", maximum(ATPall))
+ # max(G) = 20.97673324771467
+ # max(ATP) = 18.65978074314273
+ title("")
+end
+
+doPlot(0.36, 0.02, 6, 12.0)
+
+function doXY(V_in, k_l, k_p, K_m)
+
+ dt = 0.2
+ tlast = 1000
+
+ iterations = integer(round(tlast/dt))
+ ATPall = zeros(Float64, (iterations, 1))
+ Gall = zeros(Float64, (iterations, 1))
+
+ ATP = 4
+ G = 3
+ for i = 1:iterations
+ ATPall[i] = ATP
+ Gall[i] = G
+
+ dATPdt = 2 * k_l * G * ATP - (k_p * ATP) / (ATP + K_m)
+ dGdt = V_in - k_l * G * ATP
+
+ ATP = ATP + dATPdt * dt
+ G = G + dGdt * dt
+ end
+
+ tall = dt*(0:iterations-1)'
+ figure()
+ hold(true)
+ plot(Gall, ATPall, color="red")
+ hold(false)
+ xlabel("G")
+ ylabel("ATP")
+end
+
+function testStability(V_in, k_l, k_p, K_m)
+
+ dt = 0.05
+ tlast = 2000
+
+ iterations = integer(round(tlast/dt))
+ ATPall = zeros(Float64, (iterations, 1))
+ Gall = zeros(Float64, (iterations, 1))
+
+ ATP = 4
+ G = 3
+ for i = 1:iterations
+ ATPall[i] = ATP
+ Gall[i] = G
+
+ dATPdt = 2 * k_l * G * ATP - (k_p * ATP) / (ATP + K_m)
+ dGdt = V_in - k_l * G * ATP
+
+ ATP = ATP + dATPdt * dt
+ G = G + dGdt * dt
+ end
+
+ #deltaATP = maximum(ATPall[length(ATPall)/2:end]) - minimum(ATPall[length(ATPall)/2:end])
+ #deltaG = maximum(Gall[length(Gall)/2:end]) - minimum(Gall[length(Gall)/2:end])
+ #return (deltaATP, deltaG)
+ return (maximum(ATPall[length(ATPall)/2:end]),
+ minimum(ATPall[length(ATPall)/2:end]),
+ maximum(Gall[length(Gall)/2:end]),
+ minimum(Gall[length(Gall)/2:end]), )
+end
+
+function doBistable()
+ x = 0.1:0.05:1.6
+ varATP = zeros(length(x))
+ varG = zeros(length(x))
+ ATP_h = zeros(length(x))
+ ATP_l = zeros(length(x))
+ G_h = zeros(length(x))
+ G_l = zeros(length(x))
+ for i=1:length(x)
+ (a_h, a_l, g_h, g_l) = testStability(x[i], 0.02, 6, 12.0)
+ varATP[i] = a_h - a_l
+ varG[i] = g_h - g_l
+ ATP_h[i] = a_h
+ ATP_l[i] = a_l
+ G_h[i] = g_h
+ G_l[i] = g_l
+ println((a_h, g_h))
+ end
+ figure()
+ hold(true)
+ plot(x, varG, color="blue")
+ plot(x, varATP, color="red")
+ xlabel("V_in")
+ ylabel("Stability")
+ hold(false)
+ title("Stability plot")
+
+ figure()
+ hold(true)
+ plot(x, G_h, color="blue")
+ plot(x, G_l, color="blue")
+ plot(x, ATP_h, color="red")
+ plot(x, ATP_l, color="red")
+ xlabel("V_in")
+ ylabel("Value")
+ hold(false)
+ title("Values plot")
+end
+
diff --git a/assignments/hw02/quiz2.pdf b/assignments/hw02/quiz2.pdf
new file mode 100644
index 0000000..d35f763
--- /dev/null
+++ b/assignments/hw02/quiz2.pdf
Binary files differ