0% found this document useful (0 votes)
5 views10 pages

Final Graphs

The document contains a series of Python code snippets that demonstrate various mathematical and graphical computations using libraries like NumPy and Matplotlib. It includes examples of plotting exponential, sine, cosine, and polar curves, as well as performing symbolic differentiation and solving systems of equations. Author information is consistently printed at the end of each code block.

Uploaded by

deeksha31005
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)
5 views10 pages

Final Graphs

The document contains a series of Python code snippets that demonstrate various mathematical and graphical computations using libraries like NumPy and Matplotlib. It includes examples of plotting exponential, sine, cosine, and polar curves, as well as performing symbolic differentiation and solving systems of equations. Author information is consistently printed at the end of each code block.

Uploaded by

deeksha31005
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/ 10

# importing the required modules

import numpy as np
import matplotlib.pyplot as plt

# Generate x values from -10 to 10 with a step of 0.001


x = np.arange(-10, 10, 0.001)

# Calculate y values using the exponential function


y = np.exp(x)

# Create the plot


plt.plot(x, y)

# Set the title of the plot


plt.title("Exponential curve")

# Display the grid


plt.grid()

# Show the plot


plt.show()

# Print author information


print("Deeksha. V AI&DS 2024AIDS014")

Deeksha. V AI&DS 2024AIDS014

import numpy as np
import matplotlib . pyplot as plt
x = np . arange (-10 , 10 , 0 . 001 )
y1 = np .sin ( x )
y2=np .cos ( x )
plt . plot (x , y1 ,x , y2 ) # plotting sine and cosine function together with
same values of x
plt . title (" sine curve and cosine curve ")
plt . xlabel (" Values of x")
plt . ylabel (" Values of sin (x) and cos(x) ")
plt . grid ()
plt . show ()
print(" Deeksha.V AI&DS 2024BEAIDS014")

File "<ipython-input-3-5de4d22b7d11>", line 3


x = np . arange (-10 , 10 , 0 . 001 )
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an
0o prefix for octal integers

Next steps: Fix error

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-10, 10, 0.001)


y1 = np.sin(x)
y2 = np.cos(x)

plt.plot(x, y1, x, y2)


plt.title("sine curve and cosine curve")
plt.xlabel("Values of x")
plt.ylabel("Values of sin(x) and cos(x)")
plt.grid()
plt.show()

print("Deeksha.V AI&DS 2024BEAIDS014")


Deeksha.V AI&DS 2024BEAIDS014

# plotting the circle


for i in rads :
plt . polar (i , r , 'g.')
plt . show ()

File "<ipython-input-5-7df4060a4261>", line 3


plt . polar (i , r , 'g.')
^
IndentationError: expected an indented block after 'for' statement on line 2

Next steps: Explain error

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 ()
print("Deeksha.V AI&DS 2024BEAIDS014")

File "<ipython-input-6-6f54daadb422>", line 5


rads = np . arange (0 , ( 2 * np .pi) , 0 . 01 )
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an
0o prefix for octal integers

Next steps: Fix error

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 ()
print("Deeksha.V AI&DS 2024BEAIDS014")

File "<ipython-input-7-6f54daadb422>", line 5


rads = np . arange (0 , ( 2 * np .pi) , 0 . 01 )
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an
0o prefix for octal integers

Next steps: Fix error


import numpy as np
import matplotlib.pyplot as plt

plt.axes(projection='polar') # Set up polar axes


r = 3 # Define the radius of the circle
rads = np.arange(0, (2 * np.pi), 0.01) # Generate angles in radians

# Plot the circle


for i in rads:
plt.polar(i, r, 'g.') # Plot points in polar coordinates (angle, radius, style)

plt.show() # Display the plot


print("Deeksha.V AI&DS 2024BEAIDS014") # Print author information

Deeksha.V AI&DS 2024BEAIDS014

from sympy import *


x,y = symbols('x y')
u=exp(x)*(x*cos(y)-y*sin(y)) # input mutivariable function u=u(x,y)
dux = diff (u,x) # Differentate u w.r.t x
duy = diff (u,y) # Differentate u w.r.t y
duxy = diff (dux,y) # or duxy = diff (u,x,y)
duyx = diff (duy,x) # or duyx = diff (u,y,x)
# Check the condtion uxy=uyx
if duxy == duyx :
print("Mixed partial derivatives are equal ") # Indented this line by 4 spaces
else :
print("Mixed partial derivatives are not equal") # Indented this line by 4 spaces
print("Deeksha.V AI&DS 2024BEAIDS014")

Mixed partial derivatives are equal


Deeksha.V AI&DS 2024BEAIDS014

# importing the required module


import matplotlib.pyplot as plt
x = [1,2,3,4,6,7,8] # x axis values
y = [2,7,9,1,5,10,3] # corresponding y axis values
plt.scatter(x,y) # plotting the points
plt. xlabel ('x - axis ') # naming the x axis
plt. ylabel ('y - axis ') # naming the y axis
plt.title('Scatter points ') # giving a title to my graph
plt.show() # function to show the plot
print("Deeksha.V AI&DS 2024BEAIDS014")

Deeksha.V AI&DS 2024BEAIDS014

# Plot cardioid r=5(1+cos theta )


from pylab import *
theta = linspace (0 , 2*np .pi , 1000 )
r1=5+5*cos ( theta )
polar ( theta , r1 ,'r')
show ()
print("Deeksha.v AI&DS 2024BEAIDS014")
Deeksha.v AI&DS 2024BEAIDS014

from sympy import *


r , t = symbols ('r,t') # Define the variables required as symbols
r1=4*( 1+cos ( t ) ) ; # Input first polar curve
r2=5*( 1-cos ( t ) ) ; # Input first polar curve
dr1 = diff ( r1 , t ) # find the derivative of first function
dr2 = diff ( r2 , t ) # find the derivative of secodn function
t1=r1/dr1
t2=r2/dr2
q= solve ( r1-r2 , t ) # solve r1 ==r2 , to find the point of intersection
between curves
w1=t1 . subs ({t: float ( q[1])}) # substitute the value of "t" in t1
w2=t2 . subs ({t: float ( q[1])}) # substitute the value of "t" in t2
y1= atan ( w1 ) # to find the inverse tan of w1
y2= atan ( w2 ) # to find the inverse tan of w2
w=abs( y1-y2 ) # angle between two curves is abs(w1 -w2)
print ('Angle between curves in radians is %0.3f '%( w ) )
print("Deeksha.V AI&DS 2024BEAIDS014")

File "<ipython-input-10-e70ffffef69b>", line 10


between curves
^
SyntaxError: invalid syntax

Next steps: Fix error


from sympy import *

r, t = symbols('r,t') # Define symbols for radius and angle


r1 = 4*(1 + cos(t)) # First polar curve
r2 = 5*(1 - cos(t)) # Second polar curve

# Calculate derivatives
dr1 = diff(r1, t)
dr2 = diff(r2, t)

# Calculate tangent slopes


t1 = r1/dr1
t2 = r2/dr2

# Find intersection point


q = solve(r1 - r2, t)

# Substitute intersection point into tangent slopes


w1 = t1.subs({t: float(q[1])})
w2 = t2.subs({t: float(q[1])})

# Calculate inverse tangents to get tangent angles


y1 = atan(w1)
y2 = atan(w2)

# Calculate angle between curves


w = abs(y1 - y2)

# Print the result


print('Angle between curves in radians is %0.3f ' % (w))
print("Deeksha.V AI&DS 2024BEAIDS014")

Angle between curves in radians is 1.571


Deeksha.V AI&DS 2024BEAIDS014

from sympy import *


r , t = symbols ('r,t')
r1=4*(cos ( t ) ) ;
r2=5*(sin ( t ) ) ;
dr1 = diff ( r1 , t )
dr2 = diff ( r2 , t )
t1=r1/dr1
t2=r2/dr2
q= solve ( r1-r2 , t )
w1=t1 . subs ({t: float ( q[0])})
w2=t2 . subs ({t: float ( q[0])})
y1= atan ( w1 )
y2= atan ( w2 )
w=abs( y1-y2 )
print ('Angle between curves in radians is %0.4f '% float ( w ) )
print("Deeksha.V AI&DS 2024BEAIDS014")

Angle between curves in radians is 1.5708


Deeksha.V AI&DS 2024BEAIDS014

from sympy import *


# Define symbols for radius and angle
t = Symbol('t')
r = Symbol('r')

# Define the polar curve (cardioid)


r = 4*(1 + cos(t))

# Calculate the first and second derivatives


r1 = Derivative(r, t).doit()
r2 = Derivative(r1, t).doit()

# Calculate the radius of curvature


rho = (r**2 + r1**2)**(1.5) / (r**2 + 2*r1**2 - r*r2)

# Substitute t = pi/2 to find the radius of curvature at that point


rho1 = rho.subs(t, pi/2)

# Print the result


print('The radius of curvature is %3.4f units ' % rho1)
print("Deeksha.V AI&DS 2024BEAIDS014")

The radius of curvature is 3.7712 units


Deeksha.V AI&DS 2024BEAIDS014

import numpy as np
A=np . matrix ([[1 ,2 ,-1],[2 ,1 , 4],[3 ,3 , 4]])
B=np . matrix ([[0],[0],[0]])
r=np . linalg . matrix_rank ( A )
n=A . shape [1]
if ( r==n ):
print (" System has trivial solution ") # Indented this line
else :
print (" System has", n-r , "non - trivial solution (s)") # Indented this line
print(" Deeksha. V AI&DS 2024BEAIDS024")

System has trivial solution


Deeksha. V AI&DS 2024BEAIDS024

A=np . matrix ([[1 ,2 ,-1],[2 ,1 , 4],[3 ,3 , 4]])


B=np . matrix ([[1],[2],[1]])
AB=np . concatenate (( A , B ) , axis =1 )
rA=np . linalg . matrix_rank ( A )
rAB =np . linalg . matrix_rank ( AB )
n=A . shape [1]
if ( rA==rAB ):
if ( rA==n ): # Indented this block
print ("The system has unique solution ")
print ( np . linalg . solve (A , B ) )
else : # Indented this block
print ("The system has infinitely many solutions ")
else : # Indented this block
print ("The system of equations is inconsistent ")
print(" Deeksha. V AI&DS 2024BEAIDS014")

The system has unique solution


[[ 7.]
[-4.]
[-2.]]
Deeksha. V AI&DS 2024BEAIDS014

import sympy
from sympy import Symbol, solve, Derivative
# Define variables and function
x = Symbol('x')
y = Symbol('y')
f = x**2 + x*y + y**2 + 3*x - 3*y + 4
# Compute first derivatives
d1 = Derivative(f, x).doit()
d2 = Derivative(f, y).doit()
# Find critical points by solving the system of equation
critical_points = solve([d1, d2], (x, y))
# Compute second derivatives
s1 = Derivative(f, x, 2).doit()
s2 = Derivative(f, y, 2).doit()
s3 = Derivative(Derivative(f, y), x).doit()
print("Function value and critical point analysis:")
# Access the single critical point from the dictionary
x_val = critical_points[x]
y_val = critical_points[y]
# Substitute critical points into second derivatives
q1 = s1.subs({x: x_val, y: y_val}).evalf()
q2 = s2.subs({x: x_val, y: y_val}).evalf()
q3 = s3.subs({x: x_val, y: y_val}).evalf()
# Compute delta
delta = q1 * q2 - q3**2
print(f"\nCritical Point: ({x_val}, {y_val})")
print(f"Delta: {delta}, q1: {q1}")
# Determine the nature of the critical point
if delta > 0 and q1 < 0:
print("f takes a maximum at this point") # Indented by 4 spaces
elif delta > 0 and q1 > 0:
print("f takes a minimum at this point") # Indented by 4 spaces
elif delta < 0:
print("The point is a saddle point") # Indented by 4 spaces
else:

You might also like