I wrote a Python program to calculate the Magnetic Field from a given time-varying Electric field. I used CoordSys3d from sympy.vector
I got it working this afternoon. It was giving correct answers. Then, I upgraded to the newest version of Anaconda (which updated the SymPy library), and now it throws an error when I call integrate().
Here is the error traceback:
>>> integrate( jimmy, t )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/integrals/integrals.py", line 1573, in integrate
new_args = [a.doit(**doit_flags) if isinstance(a, Integral) else a
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/integrals/integrals.py", line 1573, in <listcomp>
new_args = [a.doit(**doit_flags) if isinstance(a, Integral) else a
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/integrals/integrals.py", line 597, in doit
antideriv = self._eval_integral(
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/integrals/integrals.py", line 941, in _eval_integral
result, i = risch_integrate(f, x, separate_integral=True,
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/integrals/risch.py", line 1831, in risch_integrate
ans, i, b = integrate_hyperexponential(fa, fd, DE, conds=conds)
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/integrals/risch.py", line 1564, in integrate_hyperexponential
qa, qd, b = integrate_hyperexponential_polynomial(pp, DE, z)
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/integrals/risch.py", line 1516, in integrate_hyperexponential_polynomial
va, vd = rischDE(iDta, iDtd, Poly(aa, DE.t), Poly(ad, DE.t), DE)
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/integrals/rde.py", line 774, in rischDE
_, (fa, fd) = weak_normalizer(fa, fd, DE)
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/integrals/rde.py", line 126, in weak_normalizer
r = (a - Poly(z, DE.t)*derivation(d1, DE)).as_poly(DE.t).resultant(
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/polys/polytools.py", line 65, in wrapper
return func(f, g)
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/polys/polytools.py", line 4104, in __sub__
return f.sub(g)
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/polys/polytools.py", line 1464, in sub
_, per, F, G = f._unify(g)
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/polys/polytools.py", line 465, in _unify
dom, lev = f.rep.dom.unify(g.rep.dom, gens), len(gens) - 1
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/polys/domains/domain.py", line 686, in unify
return K0.unify_with_symbols(K1, symbols)
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/polys/domains/domain.py", line 666, in unify_with_symbols
return K0.unify(K1)
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/polys/domains/domain.py", line 725, in unify
domain = domain.get_ring()
File "/opt/anaconda3/lib/python3.8/site-packages/sympy/polys/domains/complexfield.py", line 98, in get_ring
raise DomainError("there is no ring associated with %s" % self)
sympy.polys.polyerrors.DomainError: there is no ring associated with CC
Here is the code:
import numpy as np
import sympy as smp
import matplotlib.pyplot as plt
from sympy import *
from sympy import symbols
from sympy.vector import divergence
from sympy.vector import curl
from sympy import diff
from sympy import exp
from sympy import integrate
from sympy.vector import CoordSys3D
R = CoordSys3D('R')
# Variables
X, Y, Z = symbols('X Y Z')
X = R.x
Y = R.y
Z = R.z
# Basis Unit Vectors
i,j,k = symbols('i j k')
i = R.i
j = R.j
k = R.k
# Symbols
x,t = symbols('x t')
Ex = smp.Function('Ex')(x,t)
Ey = smp.Function('Ey')(x,t)
Ez = smp.Function('Ez')(x,t)
wavenumber = symbols('k')
E_0 = symbols('E_0') # Amplitude of E field
w = symbols('w' , real=True, positive=True)
# Define Ey(x,t)
Ey = E_0 * smp.exp( 1j * (wavenumber*X - w*t ))
# The Electric Field
E = Ex*i + Ey*j + Ez*k
init_printing(use_unicode=True, wrap_line=False)
# curl E = - dB/dt
# integrate( (curl E) , t ) = - B
jimmy = curl( E )
B = -integrate( jimmy, t )
pprint( B )
B = -integrate( jimmy, t ).doit()
pprint( B )
Usually we ask users to include the full traceback when asking about errors.
In a
sympycontext I expect to see "won't integrate" description when result is an expression containing the integral sign. Similarly for "can't solve" results, where the result is the original expression, or a barely simplified one.Your case is an actual error.
So while:
it has replaced that with:
I don't know enough
sympyto understand the issue, but it is more informative than "won't integrate".