Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double Asterisk

Tags:

python

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
like image 515
DaiWei Avatar asked Nov 30 '22 17:11

DaiWei


2 Answers

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: enter image description here

So the Python line should be:

T[i+1] = m*v[i+1]**2/L + m*g*cos(s[i+1]/L)
like image 77
Delimitry Avatar answered Dec 03 '22 05:12

Delimitry


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

like image 27
Frank V Avatar answered Dec 03 '22 05:12

Frank V