VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-differentiate-the-given-polynomial/

⇱ Program to differentiate the given Polynomial - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to differentiate the given Polynomial

Last Updated : 17 Feb, 2023

Given polynomial string str, the task is to differentiate the given string and print the string after differentiating it. 
Note: The input format is such that there is a white space between a term and the ‘+’, ’-’ symbol
Examples: 

Input: str = "4X3 + 3X1 + 2X2
Output: "12X2 + 3X0 + 4X1
Explanation: 
The derivative of p(x) = A*XN is p'(x) = A * N * XN - 1
Input: str = "5X4 + 6X2 + 5X2
Output: "20X3 + 12X1 + 10X1"  

Approach: The idea is to observe that when the given equation consists of multiple polynomials 

, the differentiation of the given polynomial 

. And, it is known that the derivative of 

is 

Therefore, we split the given string and differentiate every term in it. 
Below is the implementation of the above approach:
 


Output: 
20X^3 + 12X^1 + 10X^1

 
Comment
Article Tags:
Article Tags: