The Nutty Professor
All submissions for this problem are available.
Vismay Buch a mathematics fundoo professor was teaching a computer science class which was very notorious, Vismay entered and the whole class began to burst shouting WE WANT OFF!!!, Vismay got frustrated and gave them a assignment that they should write a program to solve a Numerical differential equation.
Now think that you are one among the class guys, so its now your turn to write this program. It's time you show Vismay that you are not only notorious but also are intelligent.
The problem statement goes like this.
You will be asked, given a function of x, and a numerical value a, to output the value of the derivative of the given function (with respect to x), when x=a.
The given function will only involve the single variable x (though it may appear more than once in the function), floating-point constants, and the four operators +, -, *,/, representing addition, subtraction, multiplication, and division, respectively.
Remember: if f and g are functions of x, then the following are true (where f' denotes the derivative of f):
(f + g)' = f' + g' (f - g)' = f' - g' (f * g)' = f' * g + f * g' (f / g)' = (f' * g - f * g') / (g ^ 2)
The input will consist of problems. Each input line will consist of the floating-point value a, a space, and a function f. The function f will be written in postfix notation: f will be represented as a list of words, separated by whitespace. Each word will be either a floating-point constant, the symbol x, or one of the four arithmetic operators above.
For example, the input line would be asking you to compute the derivative of the function f=(x-3.23)/(2x+7) (which happens to be f'=13.46/((2x+7)^2)), and to substitute the value 1.72 for x, resulting in the value 0.123493 (to six decimal places).
You may assume that the input is well-formed.and there will be multiple test cases in the file and a # denotes the end of the file.
For each line of input consisting of the floating-point value a and a function of f of x, output the value of f'(a), rounded to six decimal places (with a 0 before the decimal point if the magnitude of the result is less than 1).
Sample Input 1.72 x 3.23 - 2 x * 7 + / 12 x 15 7.4 # Sample Output 0.123493 1.000000 0.000000
|Time Limit:||15 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.