can compute external forces
This commit is contained in:
parent
664393aaea
commit
ee39000337
2 changed files with 25 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ import numpy as np
|
||||||
g = lgc.Const(-10)
|
g = lgc.Const(-10)
|
||||||
m = lgc.Const(1)
|
m = lgc.Const(1)
|
||||||
r = lgc.Const(1)
|
r = lgc.Const(1)
|
||||||
|
c = lgc.Const(0.3)
|
||||||
|
|
||||||
theta = lgc.Var()
|
theta = lgc.Var()
|
||||||
|
|
||||||
|
|
@ -20,13 +21,14 @@ T = 0.5 * m * (x.diff()**2 + y.diff()**2)
|
||||||
V = m * g * r * lgc.cos(theta)
|
V = m * g * r * lgc.cos(theta)
|
||||||
|
|
||||||
L = T - V
|
L = T - V
|
||||||
|
F = 0.5 * c * (x.diff()**2 + y.diff()**2)
|
||||||
|
|
||||||
init = {
|
init = {
|
||||||
theta : [-3 * 3.14/4, 0], # theta, theta.diff()
|
theta : [-3 * 3.14/4, 0], # theta, theta.diff()
|
||||||
}
|
}
|
||||||
|
|
||||||
dt = 0.01
|
dt = 0.01
|
||||||
data = L.solve(init, 10, dt, True)
|
data = L.solve(init, 10, dt, True, F)
|
||||||
|
|
||||||
# Extraire les positions
|
# Extraire les positions
|
||||||
times = sorted(data.keys())
|
times = sorted(data.keys())
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,22 @@ class Const:
|
||||||
def simplify(self):
|
def simplify(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def diff(self):
|
||||||
|
return Equation(
|
||||||
|
Operation.CONST,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Const(0)
|
||||||
|
)
|
||||||
|
|
||||||
|
def partial(self, _):
|
||||||
|
return Equation(
|
||||||
|
Operation.CONST,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Const(0)
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.value)
|
return str(self.value)
|
||||||
|
|
||||||
|
|
@ -529,7 +545,7 @@ class Equation:
|
||||||
self.compile()
|
self.compile()
|
||||||
return self.compiled_function(dico)
|
return self.compiled_function(dico)
|
||||||
|
|
||||||
def solve(self, init, tmax=10, dt=0.01, progress_bar=True):
|
def solve(self, init, tmax=10, dt=0.01, progress_bar=True, F_ext = Const(0)):
|
||||||
dico = {}
|
dico = {}
|
||||||
for v_name, v_init in init.items():
|
for v_name, v_init in init.items():
|
||||||
for i in range(len(v_init)):
|
for i in range(len(v_init)):
|
||||||
|
|
@ -541,7 +557,11 @@ class Equation:
|
||||||
equations = []
|
equations = []
|
||||||
# print([v.name for v in variables])
|
# print([v.name for v in variables])
|
||||||
for var in variables:
|
for var in variables:
|
||||||
equations.append(self.partial(var.diff().name).diff() - self.partial(var.name))
|
equations.append(
|
||||||
|
self.partial(var.diff().name).diff()\
|
||||||
|
- self.partial(var.name)\
|
||||||
|
+ F_ext.partial(var.diff().name)
|
||||||
|
)
|
||||||
|
|
||||||
unknown = self.getUnknown(dico)
|
unknown = self.getUnknown(dico)
|
||||||
for eq in equations:
|
for eq in equations:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue