English 中文(简体)
在我的职能结束时,“回归”似乎在发挥作用[重复]。
原标题:"Return" at the end of my function doesn t seem to be working [duplicate]
  • 时间:2024-04-27 02:58:25
  •  标签:
  • python

我有一项功能,意在模拟骨干的轨迹,基本考虑是电梯和拖拉。 弱肉体上的部队是电梯、拖拉和重力。 它有一个预先确定的发射角,即“theta_0”(指确定速度的角角)和角,其中描述了与横向“β”相对的星体。 之后,它每次都使用一个坡道来计算位置、加速速度和速度。 它把这些内容汇编在自己的清单中。 如果胎面达到(y[-1]<0),则停止模拟。 最后,我只希望交回分别称为x和 y的x和 y职位清单。 然而,这似乎并未奏效。 我略去了一些变数,这些变数在我的代码中较早界定,以保持该职位为比值。 职能中所看到的每个变量都应加以核算。

def trajectory(x_0,y_0,theta_0,v_0, r):

  vx_0 = v_0*(math.cos(theta_0))
  vy_0 = v_0*(math.sin(theta_0))
  A = (math.pi*r**2)

  ax_0 = 0
  ay_0 = -1*g

  t = [0]
  x = [x_0]
  y = [y_0]
  vx = [vx_0]
  vy = [vy_0]
  ax = [ax_0]
  ay = [ay_0]


  for i in range(STEPS):

    theta = math.atan(vy[i]/vx[i])
    alpha = beta_0 - theta

    CD = (0.085 + 3.30*(alpha - (-0.052))**2)
    CL = (0.13 + 3.09*alpha)

    t.append(t[i]+DT)

    x.append(x[i]+vx[i]*DT)
    y.append(y[i]+vy[i]*DT)
    vx.append(vx[i]+ax[i]*DT)
    vy.append(vy[i]+ay[i]*DT)

    drag = float(((-1/2)*RHO*A*CD*alpha*vx[i]**2))
    drag_x = float((drag*math.cos(theta)))
    drag_y = float((drag*math.sin(theta)))

    lift = float(((-1/2)*RHO*A*CL*alpha*vx[i]**2))
    lift_x = float((lift*math.cos(theta)))
    lift_y = float((lift*math.sin(theta)))

    ax.append((1/m)*(-1*lift_x - drag_x))
    ay.append((1/m)*(-m*g + lift_y - drag_y))

    if y[-1]<0:
      del(y[-1])
      del(x[-1])
      del(vx[-1])
      del(vy[-1])
      del(ax[-1])
      del(ay[-1])
      break


  return x,y

trajectory(x_0,y_0,theta_0,v_0,r)
print (x)

上面的法典在试图打印时,将重复“x”这一错误。 如果我把X和 y的打印说明放在这一职能中,那么,这些声明是印刷的,但我想提出我的结果,因此,我需要选择把名单归还给我。 我知道该法典还有其他问题,但我现在不担心这些问题,我只想知道造成这一错误的原因是什么。 感谢!

问题回答

你没有给你的职责分配任何东西。

Try:

x,y = trajectory(x_0,y_0,theta_0,v_0,r)
print (x)




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签