Example #1
0
 def as_mathml(self) -> str:
     """Get a MathML representation of this covariance."""
     return mathml(self.symbolic_expr)
Example #2
0
response = []

import galgebra.ga, sympy

base = galgebra.ga.Ga('e',g=[sympy.symbols('c', real=True)**2,-1,-1,-1],coords=sympy.symbols('t,x:z',real=True))
potential = base.mv('φ',1,f=True)

response += sympy.mathml(potential.obj, printer='presentation'),

response += sympy.mathml((base.grad*base.grad*potential).obj, printer='presentation'),

import json, pathlib
pathlib.Path(__file__).resolve().parent.joinpath('response.json').write_text(json.dumps(response))
Example #3
0
response += overlap,

LowerInverse = overlap.cholesky().inv()
coefficient, energy = sympy.Matrix.diagonalize(LowerInverse @ hamiltonian @ LowerInverse.T)
coefficient = LowerInverse.T @ sympy.Matrix.hstack(*map(
    lambda column: coefficient[:, column] / coefficient[:, column].norm(),
    range(coefficient.shape[-1])))
response += energy,

assert sympy.Matrix.applyfunc(coefficient.T @ overlap @ coefficient, sympy.cancel) == sympy.eye(len(basis))#wavefunction are orthonormal
wavefunction = basis.T @ coefficient
assert sympy.Matrix.applyfunc(wavefunction.T @ wavefunction, lambda _: sympy.integrate(_, (position, 0, length)).cancel()) == sympy.eye(len(wavefunction)) #wavefunction are orthonormal
response += wavefunction.T,

numerical = ((hbar, 1), (length, 1), (mass, 1))
import scipy.linalg, numpy
numericalEnergy, numericalCoefficient = scipy.linalg.eigh(*(numpy.array(_.subs(numerical), float) for _ in (hamiltonian, overlap)))

response += sympy.Matrix(numericalEnergy).T,

response += energy.subs(numerical).evalf(),

response += sympy.Matrix(numericalCoefficient),

response += coefficient.subs(numerical).evalf(),

response = [sympy.mathml(_, printer='presentation') for _ in response]

import json, pathlib
pathlib.Path(__file__).resolve().parent.joinpath('response.json').write_text(json.dumps(response))
Example #4
0
response = []

import galgebra.ga, sympy, numpy, operator

radius, polar, azimuthal = sympy.symbols('r,theta,phi', positive=True)
X = (radius * sympy.sin(polar) * sympy.cos(azimuthal),
     radius * sympy.sin(polar) * sympy.sin(azimuthal),
     radius * sympy.cos(polar))
base = galgebra.ga.Ga('\u0411', coords=(polar, azimuthal), X=X)
#jacobian = sympy.Matrix(base.u).jacobian(base.coords)
#assert base.mv() == tuple(operator.matmul(*(numpy.array(_) for _ in (cartesian.mv(), jacobian))))
#assert base.g == sympy.trigsimp(jacobian.T @ jacobian)
#assert base.mvr() == tuple(operator.matmul(*(numpy.array(_) for _ in (base.mv(), base.g_inv))))
response += sympy.mathml(sympy.integrate((X[0]**2 + X[1]**2) * base.E().norm(),
                                         (polar, 0, sympy.pi / 2),
                                         (azimuthal, 0, sympy.pi / 2)),
                         printer='presentation'),

import json, pathlib

pathlib.Path(__file__).resolve().parent.joinpath('response.json').write_text(
    json.dumps(response))
Example #5
0
response = []

import sympy

radius, alpha, gravity = sympy.symbols('a,alpha,g', positive=True)
theta = sympy.symbols('theta', real=True)
potentialM = sympy.symbols(
    'M',
    positive=True) * gravity * radius * sympy.sin(sympy.pi - alpha - theta)
potentialm = sympy.symbols(
    'm', positive=True) * gravity * radius * sympy.sin(theta - alpha)
phi = sympy.symbols('phi', real=True)
curve = sympy.Curve([radius * sympy.cos(phi), radius * sympy.sin(phi)],
                    (phi, theta - alpha, theta + alpha))
y = sympy.symbols('y', real=True)
potentialLamda = sympy.line_integrate(
    sympy.symbols('lamda', positive=True) * gravity * y, curve, ['x', y])
motion = sympy.diff(potentialM + potentialm + potentialLamda, theta).trigsimp()
response += sympy.mathml(motion, printer='presentation'),

import json, pathlib

pathlib.Path(__file__).resolve().parent.joinpath('response.json').write_text(
    json.dumps(response))
Example #6
0
response = []

import sympy
theta = sympy.symbols('theta', real=True)
y = (sympy.symbols('l', positive=True) / 2 -
     sympy.symbols('a', positive=True) * sympy.csc(theta)) * sympy.cos(theta)
motion = sympy.diff(
    sympy.symbols('m', positive=True) * sympy.symbols('g', positive=True) * y,
    theta).trigsimp()
response += sympy.mathml(next(_ for _ in sympy.solve(motion, theta)
                              if not _.has(sympy.pi)),
                         printer='presentation'),

import json, pathlib
pathlib.Path(__file__).resolve().parent.joinpath('response.json').write_text(
    json.dumps(response))