0% found this document useful (0 votes)
3 views

Differential Assignment 2

The document outlines an assignment for a Differential Equations course, focusing on deriving and visualizing orthogonal trajectories for circles and parabolas using Python code. It includes functions to compute these trajectories and plot them using Matplotlib. Additionally, it mentions implementation diagrams, although they are not provided in the text.

Uploaded by

Haris Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Differential Assignment 2

The document outlines an assignment for a Differential Equations course, focusing on deriving and visualizing orthogonal trajectories for circles and parabolas using Python code. It includes functions to compute these trajectories and plot them using Matplotlib. Additionally, it mentions implementation diagrams, although they are not provided in the text.

Uploaded by

Haris Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT

NAME: MUHAMMAD Haris


SEMESTER: 3 BS-DS (GROUP-B)
SUBJECT: DIFFERENTIAL EQUATION
INSTITUTE OF MANAGEMENT SCIENCES
HAYATABAD, PESHAWAR (2024PYTHON CODE:

# Import required libraries


import numpy as np
import matplotlib.pyplot as plt
from sympy import symbols, diff, solve, Eq
# Function to derive orthogonal trajectories for circles
# Family of circles: (x - h)^2 + (y - k)^2 = r^2
def orthogonal_trajectories_circles(h, k, r):
x, y = symbols('x y')
circle_eq = (x - h)**2 + (y - k)**2 - r**2 # Equation of a circle
# Differentiate implicitly to find dy/dx
dy_dx = diff(circle_eq, y) / -diff(circle_eq, x)

# Orthogonal trajectory: slope = -1 / (dy/dx)


ortho_slope = -1 / dy_dx

# Integrate to find the equation of orthogonal trajectory


ortho_eq = solve(Eq(diff(y, x), ortho_slope), y)
return ortho_eq

# Visualization of circles and their orthogonal trajectories


def plot_circles_and_trajectories():
h_values = [0, 2, -3] # Different centers for each circle
k_values = [0, -1, 2] # Different y-coordinates for centers
r_values = [2, 3, 4] # Different radii

plt.figure(figsize=(10, 6))

for h, k, r in zip(h_values, k_values, r_values):


circle = plt.Circle((h, k), r, fill=False, linestyle='dashed', color='blue')
plt.gca().add_artist(circle)

# Plot orthogonal trajectories (approximated by perpendicular lines)


x = np.linspace(-10, 10, 400)
y = k + (r**2 - (x - h)**2)**0.5
y_ortho_upper = -x + h + k
y_ortho_lower = -x + h - k

plt.plot(x, y, color='blue', label='Circle')


plt.plot(x, y_ortho_upper, linestyle='dotted', color='red')
plt.plot(x, y_ortho_lower, linestyle='dotted', color='red')

plt.title("Orthogonal Trajectories of Circles")


plt.xlabel("x")
plt.ylabel("y")
plt.axhline(0, color='black', linewidth=0.5)
plt.axvline(0, color='black', linewidth=0.5)
plt.grid(True)
plt.legend(["Circle", "Orthogonal Trajectory"])
plt.axis('equal')
plt.show()
# Derivation and visualization for parabolas
def orthogonal_trajectories_parabolas(p):
x, y = symbols('x y')
# Equation of a parabola: y^2 = 4px (focus (p, 0))
parabola_eq = y**2 - 4*p*x

# Differentiate implicitly
dy_dx = diff(parabola_eq, y) / -diff(parabola_eq, x)

# Orthogonal trajectory: slope = -1 / (dy/dx)


ortho_slope = -1 / dy_dx
ortho_eq = solve(Eq(diff(y, x), ortho_slope), y)
return ortho_eq

def plot_parabolas_and_trajectories():
p_values = [1, 2, 3] # Different distances from vertex to focus

plt.figure(figsize=(10, 6))

for p in p_values:
x = np.linspace(-5, 5, 400)
y = (4 * p * x)**0.5
y_neg = -(4 * p * x)**0.5

plt.plot(x, y, color='green', label=f'Parabola (p={p})')


plt.plot(x, y_neg, color='green')

# Plot orthogonal trajectories (approximated for visualization)


y_ortho = x**2 / (4 * p)
plt.plot(x, y_ortho, linestyle='dotted', color='purple')

plt.title("Orthogonal Trajectories of Parabolas")


plt.xlabel("x")
plt.ylabel("y")
plt.axhline(0, color='black', linewidth=0.5)
plt.axvline(0, color='black', linewidth=0.5)
plt.grid(True)
plt.legend(["Parabola", "Orthogonal Trajectory"])
plt.axis('equal')
plt.show()

# Call the plotting functions


plot_circles_and_trajectories()
plot_parabolas_and_trajectories()

IMPLEMETATION DIAGRAM:1
DIAGRAM: 2

You might also like