# Python code for the above approach
# Structure of a node
class Node:
def __init__(self, data, p1, p2):
self.data = data
self.pow1 = p1
self.pow2 = p2
self.link1 = None
self.link2 = None
# Function to generate Doubly Linked
# List from given parameters
def input_equation(head, d, p1, p2):
temp = head
# If list is empty
if head is None:
# Set it as the head
# of the linked list
ptr = Node(d,p1,p2)
head = ptr
#If list is not empty
else:
# Temporarily store
# address of the head node
temp = head
while temp.link2 is not None:
temp = temp.link2
ptr = Node(d,p1,p2)
# Connect the nodes
ptr.link1 = temp
temp.link2 = ptr
return head
# Function to calculate partial derivative w.r.t. X
def derivation_with_x(head):
print("Partial derivatives w.r.t. x: ", end = "")
temp = head
while temp is not None:
if temp.pow1 != 0:
temp.data = (temp.data) * (temp.pow1)
temp.pow1 = temp.pow1 - 1
else:
temp.data = 0
temp.pow1 = 0
temp.pow2 = 0
temp = temp.link2
temp = head
if temp.data != 0:
print(" " + str(temp.data) + "(x^" + str(temp.pow1) + " y^" + str(temp.pow2) + ")", end = "")
temp = temp.link2
while temp is not None:
if temp.data != 0:
print(" + " + str(temp.data) + "(x^" + str(temp.pow1) + " y^" + str(temp.pow2) + ")", end = "")
temp = temp.link2
print()
# Function to calculate partial
# derivative w.r.t. Y
def derivation_with_y(head):
print("Partial derivatives w.r.t. y: ", end = "")
temp = head
while temp is not None:
if temp.pow2 != 0:
temp.data = (temp.data) * (temp.pow2)
temp.pow2 = temp.pow2 - 1
else:
temp.data = 0
temp.pow1 = 0
temp.pow2 = 0
temp = temp.link2
temp = head
if temp.data != 0:
print(" " + str(temp.data) + "(x^" + str(temp.pow1) + " y^" + str(temp.pow2) + ")", end = "")
temp = temp.link2
while temp is not None:
if temp.data != 0:
print(" + " + str(temp.data) + "(x^" + str(temp.pow1) + " y^" + str(temp.pow2) + ")", end = "")
temp = temp.link2
print()
#Function to calculate partial
# derivative w.r.t. XY
def derivation_with_x_y(head):
print("Partial derivatives w.r.t. xy: ", end = "")
temp = head
while temp is not None:
if temp.pow1 != 0 and temp.pow2 != 0:
temp.data = (temp.data) * (temp.pow1) * (temp.pow2)
temp.pow1 = temp.pow1 - 1
temp.pow2 = temp.pow2 - 1
else:
temp.data = 0
temp.pow1 = 0
temp.pow2 = 0
temp = temp.link2
temp = head
if temp.data != 0:
print(" " + str(temp.data) + "(x^" + str(temp.pow1) + " y^" + str(temp.pow2) + ")", end = "")
temp = temp.link2
while temp is not None:
if temp.data != 0:
print(" + " + str(temp.data) + "(x^" + str(temp.pow1) + " y^" + str(temp.pow2) + ")", end = "")
temp = temp.link2
print()
# Driver Code
if __name__ == "__main__":
#Creating doubly-linked list
head = None
head = input_equation(head, 2,3,4)
head = input_equation(head, 3,5,7)
head = input_equation(head, 1,2,6)
#Function Call
derivation_with_x(head)
derivation_with_y(head)
derivation_with_x_y(head)
# This code is contributed by lokeshpotta20.