Spyder不会运行代码 - Python

时间:2014-03-24 21:32:16

标签: python spyder

我是编程的新手,并且已经在OSX 10.9.2上的Spyder中使用python来模拟某些物理系统。我不认为这是我的代码的问题,因为它运行良好一次,但之后,当我点击运行,命令行(Python解释器,我认为它被称为?)只显示runfile(' / Users / Paddy / .. ..文件的名称),然后我不能再运行代码。即使是其他简单的小程序也不会运行。 '>>>'在命令行中已经消失。

我在网上搜索了一个解决方案,但说实话,我不确定我在寻找什么或者这是什么类型的错误,无论是Spyder中的错误还是其他错误。我的代码是否应该有某种终止'?

我已经包含了我正在处理的全部代码,只是因为那里有错误。就像我说的,即时通讯我是全新的,我不知道这是Spyder或我的代码是一个问题。任何帮助将不胜感激,我有一个迫在眉睫的截止日期!感谢

# Velocity Verlet integrator

def Verlet(x, V, dt, A):

    x_new = x + V*dt + (A(x,V,R)*dt**2)/2
    V_new = V + (A(x,V,R) + (2/(2-dt))*((((48/x_new**13)-(24/x_new**7)) - V + (0.5)*A(x,V,R)*dt + 2**(0.5) * R)) )/2 * dt
    return (x_new, V_new)


# Start main program

# Import required libraries
import numpy as np
from numpy import array, zeros
import random   

mu, sigma = 0, 0.1 # mean and variance
S = np.random.normal(mu, sigma, 1000) # Random numbers generated from gaussian



# Then the function itself



def A(x,V,R):

    Acc = (((48/x**13)-(24/x**7)) - V + 2**(0.5) * R)

    return Acc

# Set starting values for position and velocity
x = array([5])
V = array([0])




N = 1000 # integration time steps
M = 10  # save position every M timestep
dt = 1.0 / (N) # calculate timestep length in seconds

# Lists for storing the position and velocity
Xlist = zeros([1,N/M]) #define vector dimensions
Vlist = zeros([1,N/M])
# Put the initial values into the lists
Xlist[:,0] = x
Vlist[:,0] = V

# Run simulation

print "Total number of steps:", N
print "Saving location every %d steps." % (M)
print "Start."
for i in range(N/M):
    # Run for M steps before saving values
    for j in range(M):
          # Update position and velocity based on the current ones
          # and the acceleration function 
          R = random.choice(S) # selects random number from S 
          x, V = Verlet(x, V, dt, A)

    # Save values into lists
    Xlist[:, i] = x
    Vlist[:, i] = V
print ("Stop.")

print (Xlist)
print (Vlist)



L = zeros([1,N/M])

k=0
while k < 101:
    l = k+1
    L[:,l]

print (L)



# Plot results  
from matplotlib import pyplot as plt
#plt.plot(L, Xlist) 
# Set equal axis
plt.axis('equal')
# Draw x and y axis lines
plt.axhline(color="black")
plt.axvline(color="black")

#plt.show()

1 个答案:

答案 0 :(得分:1)

在你的k&lt;&lt; 101循环,因为你永远不会增加k。试试例如:

k=0
while k < 100:
    L[:,k]
    k += 1

另请注意,python是基于0的。所以你需要k从0到99为100长度向量,而不是1到100。