2

New member here, so sorry if I didn't post enough details.

I want to find the derivative of an inputted function using a String because I will use Netbeans' JFrame, say 6x^3 + 2x and output its derivative function, 18x^2 + 2. I've been experimenting around Apache Commons Math's DerivativeStructure, but I can't seem to find an answer (yet). Any kind of advice will be appreciated.

This is the example I've been experimenting around which is also found in one of the examples here in stackoverflow (Java - Computation of Derivations with Apache Commons Mathematic Library)

    DerivativeStructure x = new DerivativeStructure(1, 3, 0, 1);

    System.out.println(x.getValue());
    // Basically, x --> x^2.
    DerivativeStructure x2 = x.pow(2);
    //Linear combination: y = 4x^2 + 2x

    /*Scanner scan = new Scanner(System.in);
    System.out.println("Input function:");
    String function=scan.nextLine();*/

    DerivativeStructure y = new DerivativeStructure(4.0, x2, 2.0, x);
    System.out.println("y    = " + y.getValue());
    System.out.println("y'   = " + y.getPartialDerivative(1));
    System.out.println("y''  = " + y.getPartialDerivative(2));
    System.out.println("y''' = " + y.getPartialDerivative(3));

I'm experimenting with the parameters of DerivativeStructure. And I also think that getPartialDerivative isn't the solution.

Community
  • 1
  • 1
theMichaelG6
  • 21
  • 1
  • 3

0 Answers0