0% found this document useful (0 votes)
8 views5 pages

Lab 01

Lab 2.maths
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Lab 01

Lab 2.maths
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

12/12/24, 12:32 PM LAB-01

LAB-01: 2D Plots of Cartesian and Polar Curves.

Explicit Functions
1.1 Exponential Curve y = ex
In [3]: 1 import numpy as np
2 import matplotlib.pyplot as plt
3 x=np.arange(-10,10,0.001) # x takes the values between -10 and 10 with a step length of 0.001
4 y=np.exp(x) # Exponential function
5 plt.plot(x,y) # plotting the points
6 plt.title("Exponential curve ")# giving a title to the graph
7 plt.grid() # displaying the grid
8 plt.show() # shows the plot

1.2 Sine and cosine curves:

In [7]: 1 import numpy as np


2 import matplotlib.pyplot as plt
3 x=np.arange(-10,10,0.001)
4 y1=np.sin(x)
5 y2=np.cos(x)
6 plt.plot(x,y1,x,y2) # plotting sine and cosine fuction together with same values of x
7 plt.title("Sine curve and cosine curve")
8 plt.xlabel("Values of x")
9 plt.ylabel("Values of sin(x) and cos(x)")
10 plt.grid()
11 plt.show()

1.3 Linear curve y=x, Quadratic curve y = x2 & Cubic curve y = x3 :

localhost:8888/notebooks/Desktop/Darshan-A127/LAB-01.ipynb 1/5
12/12/24, 12:32 PM LAB-01

In [8]: 1 import matplotlib.pyplot as plt


2 import numpy as np
3 x = np.linspace (0, 2, 100)
4 plt .plot (x, x, label ='linear')
5 plt .plot (x, x ** 2, label ='quadratic')
6 plt .plot (x, x ** 3, label ='cubic')
7 plt .xlabel('x label')
8 plt .ylabel('y label')
9 plt .title ("linear, quadractic, cubic curves")
10 plt .legend ()
11 plt .show ()

Implicit Function
1.4 circle: x2 + y2 = 4
In [11]: 1 from sympy import plot_implicit,symbols,Eq
2 x,y=symbols('x,y')
3 p1=plot_implicit(Eq(x**2+y**2,4),(x,-4,4),(y,-4,4),title = 'Circle:$x^2+y^2=4$') # r= 2

Polar Curves
1.5 Cardioids r = a(1 + cosθ) and r = a(1 − cosθ) for a=3

localhost:8888/notebooks/Desktop/Darshan-A127/LAB-01.ipynb 2/5
12/12/24, 12:32 PM LAB-01

In [12]: 1 from pylab import *


2 theta = linspace (0,2*np.pi , 1000)
3 a=3
4 r1=a*(1+cos(theta))
5 r2=a*(1-cos(theta))
6 polar (theta ,r1 ,'r')
7 polar (theta ,r2 ,'g')
8 show ()

Exercise:
1.Parabola y2 =4ax
In [13]: 1 from sympy import plot_implicit,symbols,Eq
2 x,y,a =symbols('x,y,a')
3 a=2
4 p1=plot_implicit(Eq(y**2,8*x),(x,-4,4),(y,-4,4),title = 'Parabola:$y^2=4ax$')

2.Asteroid x2/3 + y2/3 = a2/3 .

localhost:8888/notebooks/Desktop/Darshan-A127/LAB-01.ipynb 3/5
12/12/24, 12:32 PM LAB-01

In [23]: 1 from sympy import plot_implicit,symbols,Eq


2 x,y,a =symbols('x,y,a')
3 a=2
4 p1=plot_implicit(Eq(x**(2/3)+y**(2/3),a**(2/3)),(x,-4,4),(y,-4,4),title = 'Asteroid:$x^(2/3)+y^

3.FOlium of De-Cartes x3 + y3 = 3axy


In [26]: 1 from sympy import plot_implicit,symbols,Eq
2 x,y,a =symbols('x,y,a')
3 a=2
4 p1=plot_implicit(Eq(x**(3)+y**(3),3*a*x*y),(x,-4,4),(y,-4,4),title = 'Folium of De-Cartes:$x^(3

4.Four leaved rose r = 2|cos2θ|


In [19]: 1 from pylab import *
2 theta = linspace (0,2*np.pi , 1000)
3 r=2*abs(cos(2* theta))
4 polar (theta ,r,'r')
5 show ()

localhost:8888/notebooks/Desktop/Darshan-A127/LAB-01.ipynb 4/5
12/12/24, 12:32 PM LAB-01

localhost:8888/notebooks/Desktop/Darshan-A127/LAB-01.ipynb 5/5

You might also like