This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (True): | |
vp.rate(500) | |
#Calculte the force using gravitationalForce function | |
star.force = gravitationalForce(star,planet1)+gravitationalForce(star,planet2)+gravitationalForce(star,planet3) | |
planet1.force = gravitationalForce(planet1,star)+gravitationalForce(planet1,planet2)+gravitationalForce(planet1,planet3) | |
planet2.force = gravitationalForce(planet2,star)+gravitationalForce(planet2,planet1)+gravitationalForce(planet2,planet3) | |
planet3.force = gravitationalForce(planet3,star)+gravitationalForce(planet3,planet1)+gravitationalForce(planet3,planet2) | |
#Update momentum, position and time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
star = vp.sphere(pos=vp.vector(0,0,0), radius=0.2, color=vp.color.yellow, | |
mass = 1000, momentum=vp.vector(0,0,0), make_trail=True) | |
planet1 = vp.sphere(pos=vp.vector(1,0,0), radius=0.05, color=vp.color.green, | |
mass = 1, momentum=vp.vector(0,30,0), make_trail=True) | |
planet2 = vp.sphere(pos=vp.vector(0,3,0), radius=0.075, color=vp.vector(0.0,0.82,0.33),#RGB color | |
mass = 2, momentum=vp.vector(-35,0,0), make_trail=True) | |
planet3 = vp.sphere(pos=vp.vector(0,-4,0), radius=0.1, color=vp.vector(0.58,0.153,0.68), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while True: | |
vp.rate(500) | |
#calculte the force using gravitationalForce function | |
star.force = gravitationalForce(star,planet) | |
planet.force = gravitationalForce(planet,star) | |
#Update momentum, position and time | |
star.momentum = star.momentum + star.force*dt | |
planet.momentum = planet.momentum + planet.force*dt | |
star.pos = star.pos + star.momentum/star.mass*dt | |
planet.pos = planet.pos + planet.momentum/planet.mass*dt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gravitationalForce(p1,p2): | |
G = 1 #real-world value is : G = 6.67e-11 | |
rVector = p1.pos - p2.pos | |
rMagnitude = vp.mag(rVector) | |
rHat = rVector / rMagnitude | |
F = - rHat * G * p1.mass * p2.mass /rMagnitude**2 | |
return F |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
planet = vp.sphere(pos=vp.vector(1,0,0), radius=0.05, color=vp.color.green, | |
mass = 1, momentum=vp.vector(0,30,0), make_trail=True ) | |
star = vp.sphere(pos=vp.vector(0,0,0), radius=0.2, color=vp.color.yellow, | |
mass = 2.0*1000, momentum=vp.vector(0,0,0), make_trail=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vpython as vp | |
vp.scene.title = "Modeling the motion of planets with the gravitational force" | |
vp.scene.height = 600 | |
vp.scene.width = 800 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
L = [(1,'Aziz','1980-10-20'),(2,'Khelifi','1990-05-07')] | |
query = """INSERT INTO Customer | |
VALUES(?,?,?)""" | |
c.executemany(query, L) | |
#executemany is the equivalent of: | |
for iterable in L: | |
c.execute(query, iterable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g = 9.8 #G force | |
M1 = 2 #bar 1 mass in kg | |
M2 = 1 #bar 2 mass in kg | |
d = 0.05 # thickness of each bar | |
gap = 2*d # distance between two parts of upper, U-shaped assembly | |
L1 = 0.5 # physical length of upper assembly; distance between axles | |
L1display = L1+d # show upper assembly a bit longer than physical, to overlap axle | |
L2 = 1 # physical length of lower bar | |
L2display = L2+d/2 # show lower bar a bit longer than physical, to overlap axle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from vpython import * | |
scene.title = "Double pendulum" | |
scene.height = 600 | |
scene.width = 800 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.colab import files | |
uploaded = files.upload() | |
## test.csv(application/vnd.ms-excel) - 28629 bytes, last modified: 11/12/2019 - 100% done | |
## train.csv(application/vnd.ms-excel) - 61194 bytes, last modified: 11/12/2019 - 100% done | |
import io | |
train = pd.read_csv(io.BytesIO(uploaded['train.csv'])) | |
test = pd.read_csv(io.BytesIO(uploaded['test.csv'])) |
NewerOlder