Advertisement
kajacx

derivation COS

Oct 9th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. public static class Cos implements CustomInterface {
  2.  
  3.         public String getName() {
  4.             return "cos";
  5.         }
  6.  
  7.         public double getValue(double[] args) {
  8.             return Math.cos(args[0]);
  9.         }
  10.  
  11.         public Function derivate(Function[] args) {
  12.             Function defFunction = new AddAndMultiply(new Function[][]{{
  13.                             new CustomFunction(new Sin(), new Function[]{args[0]})}},
  14.                     new boolean[][]{{true}});
  15.  
  16.             if (args[0] instanceof VariableX) {
  17.                 return defFunction;
  18.             }
  19.             return new AddAndMultiply(new Function[][]{{
  20.                             args[0].derivate(),
  21.                             defFunction
  22.                         }});
  23.         }
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement