Building a Polynomial in Python

I am new to Python construction, besides the basic knowledge of matplotlib.pyplot . My question is how to build multiple polynomials of a higher degree? One of the methods that I saw was to express y in terms of x and then construct the values. But I have two difficulties:

  • y and x cannot be separated.
  • I expect a closed curve (actually a complex curve)

The polynomial I'm trying to build is:

 c0 + c1*x + c2*y +c3*x*x + c4*x*y + c5*y*y + c6*x**3 + c7*x**2*y + ..... c26*x*y**5 + c27*y**6 

All coefficients c0 - c27 known. How to do it?

Also, could you offer me resources, how can I learn about building and rendering in Python?

Explanation: Sorry for not clarifying the situation clearly enough. This is not a surface equation (which includes 3 variables: x, y, and z). I had to put zero at the end: c0 + c1 * x + c2 * y + c3 * x * x + c4 * x * y + c5 * y * y + c6 * x ** 3 + c7 * x ** 2 * y + ..... c26 * x * y ** 5 + c27 * y ** 6 = 0

+6
source share
2 answers

I'm not sure I fully understood your question, but I think you want a superficial plot

 import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D x = np.arange(-5, 5, 0.25) y = np.arange(-5, 5, 0.25) X, Y = np.meshgrid(x, y) F = 3 + 2*X + 4*X*Y + 5*X*X fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_surface(X, Y, F) plt.show() 

And for resources: official documentation and pyvideos

+5
source

Your equation is a three-dimensional surface that you can build by first creating a grid of x and y values, easily achieved with numpy:

 X,Y = np.meshgrid( np.linspace( xmin, xmax, 100), np.linspace( ymin, ymax, 200) ) 

x and y are 2D arrays containing the X and Y coordinates, respectively.

Then you can calculate the z values ​​for each point in this grid using known coefficients:

 Z = c0 + c1*X + c2*Y +c3*X*X + c4*X*Y + c5*Y*Y + c6*X**3 + c7*X**2*Y + ..... c26*X*Y**5 + c27*Y**6 

After that, you can build it using matplotlib :

 from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt ax = plt.subplot(111, projection='3d') ax.plot_surface( X, Y, Z ) plt.show() 
+2
source

Source: https://habr.com/ru/post/951159/


All Articles