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)
|
||||
m = lgc.Const(1)
|
||||
r = lgc.Const(1)
|
||||
c = lgc.Const(0.3)
|
||||
|
||||
theta = lgc.Var()
|
||||
|
||||
|
|
@ -20,13 +21,14 @@ T = 0.5 * m * (x.diff()**2 + y.diff()**2)
|
|||
V = m * g * r * lgc.cos(theta)
|
||||
|
||||
L = T - V
|
||||
F = 0.5 * c * (x.diff()**2 + y.diff()**2)
|
||||
|
||||
init = {
|
||||
theta : [-3 * 3.14/4, 0], # theta, theta.diff()
|
||||
}
|
||||
|
||||
dt = 0.01
|
||||
data = L.solve(init, 10, dt, True)
|
||||
data = L.solve(init, 10, dt, True, F)
|
||||
|
||||
# Extraire les positions
|
||||
times = sorted(data.keys())
|
||||
|
|
|
|||
|
|
@ -33,6 +33,22 @@ class Const:
|
|||
def simplify(self):
|
||||
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):
|
||||
return str(self.value)
|
||||
|
||||
|
|
@ -529,7 +545,7 @@ class Equation:
|
|||
self.compile()
|
||||
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 = {}
|
||||
for v_name, v_init in init.items():
|
||||
for i in range(len(v_init)):
|
||||
|
|
@ -541,7 +557,11 @@ class Equation:
|
|||
equations = []
|
||||
# print([v.name for v 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)
|
||||
for eq in equations:
|
||||
|
|
|
|||
Loading…
Reference in a new issue