2013-03-15 5 views
0

다음 프로그램을 컴파일 할 때 오류 메시지가 나타납니다. 목표는 비선형 진자와 특정 Poincare 섹션의 동작을 분석하는 것입니다. 진자의 동작에 대한 데이터를 하나의 파일에 인쇄하고 Poincare 섹션에 해당하는 출력을 다른 파일에 인쇄하려고 시도했습니다. 다음과 같이 파이썬 쉘에 나열된/: '_io.TextIOWrapper'및 'float'에 대해 지원되지 않는 피연산자 유형

오류가 읽 io.TextIOWrapper이 오류 또는 어떻게 문제를 해결 대해 이동하는 방법에 기록됩니다 이유를 정말 이해가 안

Traceback (most recent call last): 
File "C:\Python32\Lib\site-packages\visual\examples\JMB312.py", line 39 
    thetaDotDot = -(g/L) * sin(theta) - q * thetaDot + Fd * sin(Ohm * t) 
TypeError: unsupported operand type(s) for /: '_io.TextIOWrapper' and 'float' 

. 어떤 도움을 주셔서 감사합니다!

CODE : 귀하는 중력을 저장하고 파일을 열려면 다른 값으로 g=open('JMB312 data 2.txt', 'w') 라인에서 이름을 변경하고 작업을해야 g을 사용하는

from visual import * 
from visual.graph import * 

scene.title = 'Pendulum' 
scene.autoscale = False 
scene.height = scene.width = 500 
pivot = array([0,0,0])  # pivot position of pendulum 
scene.center = pivot   # center scene on pendulum pivot 
framesPerSecond = 400 

myWindow1 = gdisplay(x=500, title = "Phase Space", xtitle="Theta", ytitle="ThetaDot", height=500, width=500) 
f1 = gdots(gdisplay=myWindow1, color = color.cyan, size = 1) 

myWindow2 = gdisplay(title="Poincare Section", xtitle="Theta", ytitle="ThetaDot",y=400, x=500, height=500, width=500) 
f2 = gdots(gdisplay=myWindow2, color = color.yellow) 

#initial conditions for pendulum 1 
g = 9.8   # gravity 
m = 1   # mass at end of rod 
L = 9.8   # length of rod 
theta = 0.2  # initial angle (from vertical) 
thetaDot = 0 # start pendulum at rest 
thetaDotDot = 0 # acceletation 
dt = 0.04  # time step 
t = 0   # time 
Fd = 1.2  # drive force coefficient 
Ohm = 2/3  # oscillatory coefficient for drive force 
q = 0.5   # coefficient of friction 

#pendulum 1 rod 
rod = cylinder(pos=pivot, axis = (L*sin(theta),-L*cos(theta),0), radius = 0.1, color=color.cyan) 

f=open('JMB312 data 1.txt','w') 

g=open('JMB312 data 2.txt','w') 

while t < 100000: #a lot of data 
    thetaDotDot = -(g/L) * sin(theta) - q * thetaDot + Fd * sin(Ohm * t) 
    thetaDot = thetaDot + thetaDotDot * dt 
    theta = theta + thetaDot * dt 

    time = str(t) 
    angle = str(theta) 
    angular_velocity = str(thetaDot) 

    if t < 750: 
     f.write(time) 
     f.write(",") 
     f.write(angle) 
     f.write(",") 
     f.write(angular_velocity) 
     f.write("\n") 

    f1.plot(pos=(theta,thetaDot)) 

    if -dt**2/4 < Fd * sin(Ohm * t) < dt**2/4: #print poincare section data to separate file   
     g.write(time) 
     g.write(",") 
     g.write(angle) 
     g.write(",") 
     g.write(angular_velocity) 
     g.write("\n") 

     f2.plot(pos=(theta,thetaDot)) 

    if theta > 2 * pi: 
     theta = theta - 2 * pi 
    if theta < -2 * pi: 
     theta = theta + 2 * pi 

    rod.axis = (L*sin(theta), -L*cos(theta), 0) 

    t = t+dt  
g.close() 
f.close() 

답변

1

.

관련 문제