Nov-11-2018, 03:34 PM
Hello to all!
I am writing a python code for my thesis and I have a simple problem that a cannot solve it. I have a dispersion polynomial equation and I want to find it's solutions and draw them. I wrote this code:
I am writing a python code for my thesis and I have a simple problem that a cannot solve it. I have a dispersion polynomial equation and I want to find it's solutions and draw them. I wrote this code:
from sympy.solvers import solve from sympy import Symbol from sympy import solve, Poly, Eq, Function, exp from sympy.abc import x, y, z, a, b import matplotlib import matplotlib.pyplot as plt import numpy as np from pylab import figure, axes, pie, title, show # Dispersion equation solve omega2=Symbol('omega2') q=Symbol('q') a=Symbol('a') c=Symbol('c') N=Symbol('N') k0=Symbol('k0') s=solve(Poly(omega2**2-(k0**2+q**2+0.25*a**2)*c**2*omega2+k0**2*c**2*N**2), omega2) print("solution 1:") print(s[0]) print() print("solution 2") print(s[1]) # Define functions # here is the issue def sol1(k0,q,a,c,N): return s[0] def sol2(k0,q,a,c,N): return s[1] # Drawing of solutions N=10 a=20.42 k0=np.arange(1,500,1) n=np.arange(1,11,1) x=k0 c=1 plt.figure(1) plt.rc('text', usetex=True) plt.rc('font', family='serif') for i in n: q=i*np.pi y2=sol1(k0,q,a,c,N) # Here functions doesn't work y1=sol2(k0,q,a,c,N) plt.plot(x,y1,'b',x,y2,'r') plt.xlabel(r'$\bar{k}^{2}_{0}$',fontsize=16) plt.ylabel(r'$\bar{\omega}^{2}$',fontsize=16) plt.title(r"Arithmetic Dispersion Diagram", fontsize=16, color='purple') plt.legend([r'$\bar{\omega}_{p}$',r'$\bar{\omega}_{g}$']) plt.ylim(1,500) plt.xlim(1,30) plt.show()The problem is that when I call the functions, if I put some arguments, always the function returns to me the same thing. But the functions depends on k0,q,a,c,N. Of course I can just copy-paste the solutions of the output and fix the bad syntax. But I have to solve 5 problems like that and the other 4 have some monster equations, that are very difficult to copy-paste and fix the syntax. So I need something smarter.