Vpython: свойство 'axis' должно быть вектором - PullRequest
0 голосов
/ 07 октября 2018

Я выполняю задание Vpython для моего класса по физике 2, в котором предлагается программировать электрическое поле диполя.Я написал следующий код:

## constants
oofpez = 9e9 # stands for One Over Four Pi Epsilon-Zero
qe = 1.6e-19  # postive charge value
s = 4e-11    # charge separation
R = 3e-10  # display Enet on a circle of radius R
scalefactor = 3e-20 # for scaling arrows to represent electric field

## objects
## Represent the two charges of the dipole by red and blue spheres:
plus = sphere(pos=vector(s/2,0,0), radius=1e-11, color=color.red)
qplus = qe   # charge of positive particle
neg = sphere(pos=vector(-s/2,0,0), radius=1e-11, color=color.blue)
qneg = -qplus  # charge of negative particle


## calculations
## You will complete the lines required to make a loop calculate and display the net dipole electric field
## at equally spaced angles on a circle radius R around the dipole. The dipole is centered at the origin.
theta = 0
while theta < 2*pi:
    rate(2)   # tell computer to go through loop slowly
    ## Calculate observation location (tail of arrow) using current value of theta:
    Earrow = arrow(pos=R*vector(cos(theta),sin(theta),0), axis=vector(1e-10,0,0), color=color.orange)
    ## assign the name TestLocation to be the observation location on the circle radius R
    TestLocation=R*vector(cos(theta),sin(theta),0)
    ## write instructions below to tell the computer how to calculate the correct 
    ## net electric field Enet at the observation location (the position of Earrow):
    rPlus=TestLocation-plus.pos
    rPlusMag=((R*cos(theta)-(s/2))^2+(R*sin(theta))^2)^0.5
    rPlusHat=rPlus/rPlusMag
    Eplus=oofpez*qplus/(rPlusMag)^2*rPlusHat

    rNeg=TestLocation-neg.pos
    rNegMag=((R*cos(theta)-(-s/2))^2+(R*sin(theta))^2)^0.5
    rNegHat=rNeg/rNegMag
    Eneg=oofpez*qneg/(rNegMag)^2*rNegHat

    Etotal=Eplus+Eneg

    Enet=arrow(pos=TestLocation,axis=Etotal*scalefactor, color=color.green)

    ## change the axis of Earrow to point in the direction of the electric field at that location
    ## and scale it so it looks reasonable
    ## Efield = arrow(pos=R*vector(cos(theta),sin(theta),0), axis=Etotal*scalefactor, color=color.blue)
    Earrow.axis=Etotal*scalefactor

    ## Assign a new value to theta
    theta = theta + pi/6

В назначении был создан готовый шаблон с комментариями, объявлены правильные переменные и переменным присвоены правильные значения, поэтому в теории все должно работать правильно, если явведите остальную часть кода правильно.Код, который я написал, начинается с «rPlus = ...» и заканчивается на «Enet = ...». Однако, когда я запускаю его (используя GlowScript IDE), он выдает сообщение об ошибке «Ошибка: свойство 'axis' должно бытьvector ", что, я уверен, означает, что что-то не так со значением, присвоенным Enet.axis в этом разделе кода.Я просмотрел сгенерированный код и не могу найти ошибку.

Мы изучаем Python в дополнение к нашей обычной курсовой работе, поэтому у меня нет опыта работы с Python, кроме этих заданий.Мне не нужна помощь в поиске электрического поля, просто почему появляется сообщение об ошибке.Мы будем благодарны за любую помощь или подсказку в правильном направлении!

Спасибо

1 Ответ

0 голосов
/ 15 ноября 2018

В строке 31 вы использовали ^ вместо ** для возведения в степень.

Если вы используете браузер Chrome, вы можете получить номер строки ошибки.

Я нашел проблему, вставивпечатать операторы в ключевых местах кода, что указывает на то, что rPlusMag был 0, а не вектором.

...