Polynomial Graph using Python

Polynomial Graph

Introduction to Polynomial Graph

Polynomial curve a is smooth and continues line of graph, connected by a series of co-ordinates calculated using a polynomial equation (For example, y = f(x), where f(x) = Ax2 + Bx + C). In this program, I have used a polynomial equation y = 3x2 + 4x + 2 with x values range from 0 to 5. The program generated co-ordinate points (x, y) in the graph will be (0, 2), (1, 9), (2, 22), (3, 41), (4, 66), and (5, 97).

Program Implementation

In this tutorial, I have used Python 3.5.2 (64-bit) software, and 7 modules: MatPlotLib 2.0.2, PyParsing 2.2.0, Python-DateUtil 2.6.1, PyTZ 2017.2, SetupTools 36.2.0, Cycler 0.10.0, and NumPy-MKL 1.13.1 implemented in Windows 10 Enterprise operating system. The 7 modules are chosen based on the compatibility of Python and OS version and bit.

Source Code

import numpy as np
import matplotlib.pyplot as plt

a = 3
b = 4
c = 2
x = np.linspace(0, 10, 256, endpoint = True)
y = (a * (x * x)) + (b * x) + c

plt.plot(x, y, '-g', label=r'$y = 3x^2 + 4x + 2$')

axes = plt.gca()
axes.set_xlim([x.min(), x.max()])
axes.set_ylim([y.min(), y.max()])

plt.xlabel('x')
plt.ylabel('y')
plt.title('Polynomial Curve')
plt.legend(loc='upper left')

plt.show()

Comments

Post a Comment

Most Popular Posts

TNEB Bill Calculator

TNEB Bill Calculator (New)

Technical Questions