Пример #1
0
 @NotNull
 Polynomial derivative() {
   @NotNull Polynomial deriv = new Polynomial(z_value, variableCode, oldvariablecode, consts);
   deriv.setSigns(this.signs);
   for (int i = 0; i < terms.size(); i++) {
     deriv.terms.add(terms.get(i).derivative());
   }
   return deriv;
 }
Пример #2
0
 @Override
 protected String derivativeBase(int order) {
   if (order < 0) {
     throw new IllegalArgumentException(UNSUPPORTED_DERIVATIVE_ORDER_MESSAGE);
   }
   Polynomial derived = this;
   for (int i = 0; i < order; ++i) {
     derived = derived.derivative();
   }
   return derived.toString();
 }
Пример #3
0
 Polynomial fromString(String polynomial, boolean deepEvaluate) {
   if (deepEvaluate) {
     String[] divisors = StringManipulator.split(polynomial, ",/,");
     Polynomial[] dividing = new Polynomial[divisors.length];
     for (int i = 0; i < divisors.length; ++i) {
       String[] multipliers = StringManipulator.split(divisors[i], ",*,");
       Polynomial[] multiplying = new Polynomial[multipliers.length];
       for (int j = 0; j < multipliers.length; ++j) {
         multiplying[j] =
             new Polynomial(null, variableCode, oldvariablecode, consts)
                 .fromString(multipliers[j], variableCode, oldvariablecode, consts, false);
       }
       Polynomial multiplied = multiplying[0];
       for (int j = 1; j < multiplying.length; ++j) {
         multiplied.multiply(multiplying[j]);
       }
       dividing[i] = multiplied;
     }
     Polynomial divided = dividing[0];
     for (int i = 1; i < dividing.length; ++i) {
       divided.divide(dividing[i]);
     }
     init(divided);
     return this;
   }
   @NotNull String[] tokens = split(polynomial, ",");
   terms.ensureCapacity(tokens.length);
   signs.ensureCapacity(tokens.length + 1);
   for (@NotNull String token : tokens) {
     if (token.equals("+") || token.equals("-")) {
       signs.add(token.trim());
     } else {
       terms.add(new Term(variableCode, oldvariablecode, consts).fromString(token.trim()));
     }
   }
   if (signs.size() == terms.size() - 1) {
     signs.add(0, "+");
   }
   return this;
 }