0
import matplotlib.pyplot as plt
import numpy as np
import scipy as sc
import math


t,theta1=np.loadtxt('Single Small Angle 1.txt',unpack=True,skiprows=2)
t2,theta2=np.loadtxt('Single Small Angle 3.txt',unpack=True,skiprows=2)
theta=[]

omega=np.arange(int(len(theta1)/5)-1)
for x in range (int(len(theta1)/5-1)): 
    omega[x]=(theta1[x*5]-theta1[(x+1)*5])/.005
    theta[x]=theta1[x*5]


plt.plot(theta1,omega)
plt.xlabel("${\Theta}$ [rad]")
plt.ylabel("${\Omega}$ [rad/s]")
plt.title("Small Angle Approximation Phase Space")
plt.show()

Traceback (most recent call last):
    theta[x]=theta1[x*5]
IndexError: list assignment index out of range
[Finished in 0.6s with exit code 1]

I have no clue what I'm doing and I just want to fix the error. I'm just trying to make a phase space and I need the derivative of my theta1 stuff so I can have d(theta1)/dt.

laike9m
  • 18,344
  • 20
  • 107
  • 140
user3291404
  • 781
  • 1
  • 5
  • 5
  • 3
    This question appears to be off-topic because the OP says `I have no clue what I'm doing and I just want to fix the error`. – devnull Feb 10 '14 at 04:25
  • My TA sent me the majority of code and I have had to tweak it to fix it. But anytime I ask him a question he just makes a new error and he has basically told me he's quitting on it for the night. – user3291404 Feb 10 '14 at 04:27
  • 1
    `But anytime I ask him a question he just makes a new error ...` -- In that event it appears that he doesn't deserve to be a TA. – devnull Feb 10 '14 at 04:29

1 Answers1

1

The below should work -- your problem was not initializing theta with the proper length. You could equally well insert the line omega=np.arange(int(len(theta1)/5)-1). This creates both as lists, then appends to them, and I think it reads a bit better.

theta, omega = [],[]
for x in range (int(len(theta1)/5-1)): 
  omega.append((theta1[x*5]-theta1[(x+1)*5])/.005)
  theta.append(theta1[x*5])

omega = np.array(omega)
theta = np.array(theta)
colcarroll
  • 3,632
  • 17
  • 25