Program to Plot Sine function?

Program to Plot Sine function?

Sine function in Mathematics: In this section, first of all, we learn about the Program to Plot Sine function in Mathematics.

In mathematics, if talk about sine function. It is a trigonometric function of an angle. The sine of an acute angle is defined in the context of a right triangle: for the specific angle, it is the ratio of the size of the aspect that is opposite that angle to the length of the longest aspect of the triangle. 

More generally, the definition of sine (and other trigonometric functions) can be prolonged to any real cost in terms of the size of a positive line section in a unit circle. More modern-day definitions categorical the sine as a limitless sequence or as the solution of positive differential equations, permitting their extension to arbitrary positive and negative values and even to complex numbers.

Sine function in Python:


Now we read about sine function in python. How we can use Sine function in python along with syntax.


sin():- This feature returns the sine of value that passed as an argument. The value that is passed gives results in radians. sin() function is used to discover the sine of given argument in radians. The sine is a trigonometric function that represents the ratio between the hypotenuse and the opposite. sine() function is a section of python programming language.


Syntax of sin() Function: The syntax of sin() function in Python is given below:

math.sin(x)

It will return the value of sin() Function in Python.sin() function returns the sine of a given input in radians. In the case of the Sine function, we need to import math or we can say that we can't use sin function without math module.

But in this article, we implement the sine function with matplotlib and numpy. you can also be used math module when it gives results in radians. so we can implement using numpy. we discuss here how to use numpy.sin() in Python along with code and also discuss Program to Plot Sine function? in Python programming.

numpy.sin() in Python:

numpy.sin(x[, out]) = func ‘sin’) : 

This mathematical function used to calculate trigonometric sine for all x(being the array elements). NumPy contains a wide range of various mathematical operations. It provides standard trigonometric functions that return trigonometric ratios for a given angle in radians, functions for arithmetic operations and handling complex numbers.

np.sin() Trigonometric Function
np.sin() - NumPy function helps to find out the sine value of the angle in degree and radian.

Python Code:

import numpy as np
from matplotlib import pyplot as plt
x = np.arange(
0,3*np.pi,0.01)
a =
5
b = 4
y = np.sin(a*x+b)
plt.plot(x,y)
plt.xlabel(
'x values')
plt.ylabel(
'y values')
plt.title(
'sin function')
plt.grid(
True)
plt.show()


Output:
Program to Plot Sine function?
Program to Plot Sine function











Summary: In this article, we discuss the Sine function in detail. first of all, we discuss sine function in mathematics, the definition of the sine function and how actually it is used in mathematics. then we discuss sine function in Python along with the syntax of the sine function in python. there are two ways we used sin() function in python. The first one is math.sin(x) in this case we need to import the math module. the second one is numpy.sin() using numpy and matplotlib for plotting graph of the sine function. 

In the last, we discuss the code for the Plotting the graph of the sine function with output. In this code first, we need to import numpy and we used numpy as np then we need to import matplotlib which is necessary to plot a graph. so we defined matplotlib as plt. In this matplotlib.pyplot is a collection of functions that make matplotlib work like MATLAB. 

For pyplot function makes some change to a figure: e.g., creates a figure, creates a plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.