简体   繁体   中英

Double Asterisk

I'm new to Python and really stumped on this. I'm reading from a book and the code works fine; I just don't get it!

T[i+1] = m*v[i+1]ˆ**/L

What's with the double asterisk part of this code? It's even followed by a forward slash. The variable L is initialized with the value 1.0 However, it looks like someone slumped over the keyboard, but the code works fine. Is this a math expression or something more? I would appreciate the help understanding this. Thanks!

full code:

from pylab import *
g = 9.8 # m/sˆ2
dt = 0.01 # s
time = 10.0 # s
v0 = 2.0 # s
D = 0.05 #
L = 1.0 # m
m = 0.5 # kg
# Numerical initialization
n = int(round(time/dt))
t = zeros(n,float)
s = zeros(n,float)
v = zeros(n,float)
T = zeros(n,float)
# Initial conditions
v[0] = v0
s[0] = 0.0
# Simulation loop
i = 0
while (i<n AND T[i]>=0.0):
    t[i+1] = t[i] + dt
    a = -D/m*v[i]*abs(v[i])-g*sin(s[i]/L)
    v[i+1] = v[i] + a*dt
    s[i+1] = s[i] + v[i+1]*dt
    T[i+1] = m*v[i+1]ˆ**/L + m*g*cos(s[i+1]/L)
    i = i + 1

This code is from the book "Elementary Mechanics Using Python: A Modern Course Combining Analytical and Numerical Techniques".
According to the formula on the page 255: 在此输入图像描述

So the Python line should be:

T[i+1] = m*v[i+1]**2/L + m*g*cos(s[i+1]/L)

What's with the double asterisk part of this code?

The answer to your core questions (at least as it exists of this writing) is the double asterisk (star) is power -- "raise to the power". So, i**3 would be "cube i ".

My (cross check) source: https://stackoverflow.com/a/1044866/18196

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM