In my program, I'm using sympy to get an analytical expression for a set of constants (r, a, b and tau) then plot the graph of r as a function of l. Firstly, I define my constants as such:
import sympy
import numpy
import matplotlib.pyplot as plt
[z1, z2, z3, k2] = [1, 2, 4, 2 * numpy.pi]
l = sympy.Symbol('l')
r = sympy.Symbol('r')
tau = sympy.Symbol('tau')
base = numpy.linspace(0, 10, 10000)
I then define and calculate my matrices (where M2 is the transpose of [r, a, b, tau]):
M1 = sympy.Matrix([[-1, 1, 1, 0],
[1, z1/z2, - z1/z2, 0],
[0, sympy.exp(- 1j * k2 * l), sympy.exp(1j * k2 * l), -1],
[0, - sympy.exp(- 1j * k2 * l), sympy.exp(1j * k2 * l), z2/z3],
])
M3 = sympy.Matrix([[1], [1], [0], [0]])
M2 = (M1 ** -1) * M3
I then try to plot this using:
sympy.plot(M2[0].subs(l, base), base)
Which results in the following error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm 2020.2.3\plugins\python\helpers\pydev \_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2020.2.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "matrix solver.py", line 47, in <module>
sympy.plot(M2[0].subs(l, base), base)
File "AppData\Local\Programs\Python\Python39\lib\site-packages\sympy\plotting\plot.py", line 1641, in plot
plot_expr = check_arguments(args, 1, 1)
File "AppData\Local\Programs\Python\Python39\lib\site-packages\sympy\plotting\plot.py", line 2302, in check_arguments
assert all(isinstance(e, Expr) for expr in exprs for e in expr)
AssertionError


