Maths Lab 1
Maths Lab 1
1E # A simple graph
import matplotlib . pyplot as plt
import numpy as np
x = np . linspace (0 , 2 , 100 )
plt . plot (x , x , label ='linear ') # Plot of y=x a linear curve
plt . plot (x , x ** 2 , label ='quadratic ') # Plot of y=x^2 a
quadric curve
plt . plot (x , x ** 3 , label ='cubic ') # Plot of y=x^3 a cubic
curve
plt . xlabel ('x label ') # Add an x- label to the axes .
plt . ylabel ('y label ') # Add a y- label to the axes .
plt . title (" Simple Plot ") # Add a title to the axes .
plt . legend () # Add a legend
plt . show () # to show the complete graph
LAB1 2D-Plots of Cartesian and Polar Curves
1F from sympy import plot_implicit , symbols , Eq
x , y = symbols ('x y')
p1 = plot_implicit ( Eq ( x ** 2 + y ** 2 , 4 ) ,(x ,-4 , 4 ) ,(y ,-4 , 4
) , title = 'Circle : $x^2+y^2=4$ ') # r= 2
p3= plot_implicit ( Eq (( y ** 2 )*( 2-x ) , ( x ** 2 )*( 2+x ) ) , (x ,
-5 , 5 ) , (y , -5 , 5 ) , title = 'Strophoid : $y^2 (a-x)=x^2 (a+x), a>
0$ ') # a=2
p4= plot_implicit ( Eq (( y ** 2 )*( 3-x ) ,x ** 3 ) ,(x ,-2 , 5 ) ,(y ,-
5 , 5 ) ) # a=3
p5= plot_implicit ( Eq ( 4*( y ** 2 ) ,( x ** 2 )*( 4-x ** 2 ) ) ,(x ,-
5 , 5 ) ,(y ,-5 , 5 ) ) # a=2
p6= plot_implicit ( Eq ( x ** 3+y ** 3 , 3*2*x*y ) ,(x ,-5 , 5 ) ,(y
,-5 , 5 ) ) # a=2
1G import numpy as np
import matplotlib . pyplot as plt
plt.axes(projection = 'polar')
r=3
rads = np.arange( 0, (2*np.pi), 0.01 ) # plotting the circle
for i in rads :
plt.polar(i , r , 'g.')
plt.show ()
1K import numpy as np
import matplotlib.pyplot as plt
def circle ( r ):
x = [] # create the list of x coordinates
y = [] # create the list of y coordinates
for theta in np . linspace (-2*np.pi, 2*np.pi, 100): # loop
over a list of theta , which ranges from -2 pi to 2 pi
x.append ( r*np .cos( theta ) ) #add the corresponding
expression of x to the x list
y.append ( r*np .sin( theta ) ) # same for y
plt.plot(x , y ) # plot using matplotlib . piplot
plt.show () # show the plot
circle( 5 ) # call the function
LAB1 2D-Plots of Cartesian and Polar Curves
1L import numpy as np
import matplotlib . pyplot as plt
def cycloid ( r ):
x = [] # create the list of x coordinates
y = [] # create the list of y coordinates
for theta in np.linspace(-2*np.pi, 2*np.pi, 100 ): # loop over
a list of theta , which ranges from -2 pi to 2 pi
x.append(r*(theta - np.sin(theta))) #add the
corresponding expression of x to the x list
y.append(r*(1 - np.cos(theta))) # same for y
plt.plot(x,y) # plot using matplotlib . piplot
plt.show() # show the plot
cycloid(2) # call the function