# Monday recap – Python, Trapezoidal Method, SQL, Samantha Powers…

Today started out frustrating, although it wasn’t a bad day. It took me three hours to figure out the trapezoidal method of integration, because none of the descriptions I could find were very clear. I coded it up in Python – The annoying thing being, that I’m learning Python concurrently. This is all for a class in Nonlinear Dynamics, one of the big tools for complexity science. The next thing I need to do is learn to plot the results; for now, I am copy-pasting into Excel and letting it create a chart. Sadly, such tutorials as there are on the web do not allow me to get up and running quickly for plotting the graphs I need. I’ll just add it to the list…

I also read through a chapter of SQL (database language) on scripts. For our semester project, I have decided to create a fictitious library that will use my not-fictitious collection of books. For this week’s assignment, we need to create a script that is logical for our business; I’m pondering what that might be for my library.

Finally, reading. I’m working my way through Samantha Power‘s book on Genocide. It’s painful reading, mainly because of the inaction of the United States on the subject over the years. I don’t know what the answer is; I’m not a huge fan of R2P (Responsibility to Protect). But inaction doesn’t seem to be a good answer either.

That’s all for today. Below is the Python code I wrote for the Trapezoidal method for a Simple Harmonic Oscillator.

print(“Welcome:”)
g = input(“Enter X Sub 0: “)
Xsub0 = float(g)
h = input(“Enter V sub 0: “)
Vsub0 = float(h)
B = input(“Enter Friction (B): “)
friction = float(B)
g = input(“Enter Gravity (g): “)
gravity = float(g)
m = input(“Enter Mass (m): “)
mass = float(m)
k = input(“Enter Spring Constant (K): “)
KConstant = int(k)
t = input(“Enter time step (del-t): “)
deltaT = float(t)
e = input(“Enter end time: “)
endTime = float(e)

i = 0.0
Xnow = Xsub0
Vnow = Vsub0
while i <= endTime:
vprime = gravity – ((friction/mass) * Vnow) – ((KConstant/mass) * Xnow)
vODE = vprime
xODE = Vnow
vectorX = deltaT * xODE
vectorV = deltaT * vODE
XNew = Xnow + vectorX
VNew = Vnow + vectorV
Xone = XNew
Vone = VNew

vprime = gravity – ((friction/mass) * VNew) – ((KConstant/mass) * XNew)
vODE2 = vprime
xODE2 = VNew
vectorX = (deltaT * .5) * (xODE + xODE2)
vectorV = (deltaT * .5) * (vODE + vODE2)
XNew = Xnow + vectorX
VNew = Vnow + vectorV

Xnow = XNew
Vnow = VNew

###print(“X at ” + str(i) + ” is ” + str(XNew) + “\t\t\t” + “V at ” + str(i) + ” is ” + str(VNew))
print(str(XNew) + “\t\t\t” + str(VNew))
i += deltaT