Python Forum
To draw a polynomial solution
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
To draw a polynomial solution
#1
I just want to draw a polynomial solution and I have always the same error. I need this program to complete my thesis. I'm new in python. Please help!!!
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.pyplot as plt
import numpy as np

def coef0(k0,c,N):
    return k0**2*c**2*N**2
def coef1(k0,q,a):
    return -(k0**2+q**2+0.25*a**2)
def coef2(k0):
    return 1
def sols(a0,a1,a2):
    omg2=Symbol('omg2')
    c=solve(Poly(a2*omg2**2+a1*omg2+a0),omg2)
    return c

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
    c0=coef0(k0,c,N)
    c1=coef1(k0,qq,a)
    c2=coef2(k0)
    y1,y2=sols(c0,c1,c2)
    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()
Hint: I tried also to create a scatter with a for loop j in k0, but always the same problem. The error is: "can't initialize from 'list' without generators"
Reply
#2
(Nov-13-2018, 12:54 PM)pianistseb Wrote: I have always the same error.
Please, read What to include in a post

Post the full traceback in error tags
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
I finally found the solution. How can I delete the post?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can I evaluate a Chebyshev polynomial using a function player1681 1 1,987 Nov-22-2019, 06:33 AM
Last Post: scidam
  Machine Learning Polynomial Regression braveYug 0 1,704 Nov-13-2019, 11:41 AM
Last Post: braveYug
  Confidence intervals over time with polynomial regression jjameson 0 3,298 May-16-2019, 02:22 PM
Last Post: jjameson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020