Graph Plotter for Two Mathematical
Functions
Flowchart:
Algorithm:
1.Input:
○ Accept the starting and ending values for the range.
○ Accept the number of data points to be used.
○ Accept the two mathematical functions as input.
2.Define Functions:
○ Define a function to calculate the value of the first
mathematical expression.
○ Define a function to calculate the value of the second
mathematical expression.
3.Generate Data:
○ Create a sequence of data points within the specified
range using the chosen number of points.
4.Compute Values:
○ Compute the values of the first function for each data
point.
○ Compute the values of the second function for each
data point.
5.Plot the Graphs:
○ Plot the graph for the first function with appropriate
markers and line styles.
○ Plot the graph for the second function with appropriate
markers and line styles.
○ Add a grid to the plot.
○ Label the axes and set the plot title.
○ Add a legend to differentiate between the two
functions.
6.Display the Plot:
○ Show the plot with the two functions visualized.
Program Source Code:
#Assignment9
#UME20241002
import numpy as np
import matplotlib.pyplot as plt
a=int(input("enter the initial value of x: "))
b=int(input("enter the final value of x: "))
n=int(input("enter the data points to be added: "))
s=input("enter the first function to be plotted: ")
s2=input("enter the second function to be plotted: ")
def F(x):
f=eval(s)
return(f)
def G(x):
g=eval(s2)
return(g)
x=np.linspace(a,b,n)
y=F(x)
z=G(x)
plt.plot(x,y,color='orange',marker='o',linestyle='dotted')
plt.plot(x,z,color='purple',marker='o',linestyle='dotted')
plt.grid()
plt.xlabel("x")
plt.ylabel(f"{s} and {s2}")
plt.title(f"graph of {s} and {s2} vs x")
plt.legend([f"{s}",f"{s2}"])
plt.show()
Sample output:
enter the initial value of x: 0
enter the final value of x: 9
enter the data points to be added: 101
enter the first function to be plotted: np.sin(x)
enter the second function to be plotted: np.cos(x)