How to handle a function input

Viewed 38

I need to make a program that calculates the average rate of change of a function.

And my struggle is how to deal with the function input.

I need my program be able to understand a function and replace x per values.

Example:

Write the function:

input: f(x) = x^3 - 9x

Write the x value:

input: 9

I need the program, to automatic replace the function values with the x value, i mean like this:

f(9) = 9^3 - 9x9

I was thinking code this in java, but i have no required language, can be any one.

1 Answers

You've basically answered the question with your pseudo code! I don't know Java, but I'll do my best.

public static void main(float xVariable){
  float answer = Math.pow(xVariable, 3) - (9 * xVariable)
  System.out.println(answer);
}

Hopefully that's pretty close!

Related