James K J
James K J

Reputation: 615

Create a function that differentiates a polynomial for a given value of x?

I have come across this question which is given below

Create a function that differentiates a polynomial for a given value of x.
Your function will receive 2 arguments:  a polynomial as a string, 
and a point to evaluate the equation as an integer.

differenatiate("12x+2", 3)      ==>   returns 12
differenatiate("x^2+3x+2", 3)   ==>   returns 9
differentiate("x^2-x", 3),      ==>   returns 5
differentiate("-5x^2+10x+4", 3),==>   returns -20

To be honest, I didn't understand the question by definition. So I decided to understand the question through test cases, but I couldn't. If anyone can understand what the question is all about, please help me to understand it.

I am not seeking for a solution to this question

Upvotes: 2

Views: 416

Answers (1)

tomkot
tomkot

Reputation: 956

The function should compute the value of the derivative of the polynomial at the given x value.

  • The derivative of 12x+2 is 12.

  • The derivative of xˆ2+3x+2 is 2x+3, and plugging in x=3 gives 2*3+3=9.

  • The derivative of xˆ2-x is 2x-1. Setting x=3 gives 2*3-1=5.

  • The derivative of -5x^2+10x+4 is -10x+10. Setting x=3 gives -10*3+10=-20.

Upvotes: 3

Related Questions