Advertisement
Guest User

Untitled

a guest
May 6th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.Map;
  2. import java.util.TreeMap;
  3.  
  4. public class Plus extends BinaryExpression implements Expression{
  5.  
  6.     //constructor
  7.     public Plus(Expression firstExp, Expression secondExp){
  8.         super(firstExp, secondExp);
  9.     }
  10.    
  11.     protected Expression getOperation(Expression first, Expression second) {
  12.         return new Plus(first,second);
  13.     }
  14.    
  15.     protected String getOperationString() {
  16.         return "+";
  17.     }
  18.  
  19.     protected double returnExp(double first, double second) {
  20.         return first + second;
  21.     }
  22.  
  23.     protected Expression getDifRules(Expression first, Expression second, Expression
  24.             firstDx, Expression secondDx) {
  25.         return new Plus(firstDx,secondDx);
  26.     }
  27.    
  28.    
  29.     public static void main(String args[]) throws Exception {
  30.         Expression e2 = new Sin(new Var("x"));
  31.         System.out.println(e2);
  32.         System.out.println(e2.differentiate("x"));
  33.         Expression e = new Div(new Num(1),new Var("y"));
  34.         System.out.println(e);
  35.         System.out.println(e.differentiate("y"));
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement