Java Code Examples for org.apache.commons.math3.analysis.differentiation.DerivativeStructure#multiply()

The following examples show how to use org.apache.commons.math3.analysis.differentiation.DerivativeStructure#multiply() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    for (int i = 0; i < (m - 2); ++i) {
        double div = (i + 1) / 29.0;
        DerivativeStructure s1 = variables[0].getField().getZero();
        DerivativeStructure dx = variables[0].getField().getOne();
        for (int j = 1; j < n; ++j) {
            s1 = s1.add(dx.multiply(j).multiply(variables[j]));
            dx = dx.multiply(div);
        }
        DerivativeStructure s2 = variables[0].getField().getZero();
        dx = variables[0].getField().getOne();
        for (int j = 0; j < n; ++j) {
            s2 = s2.add(dx.multiply(variables[j]));
            dx = dx.multiply(div);
        }
        f[i] = s1.subtract(s2.multiply(s2)).subtract(1);
    }

    DerivativeStructure x1 = variables[0];
    DerivativeStructure x2 = variables[1];
    f[m - 2] = x1;
    f[m - 1] = x2.subtract(x1.multiply(x1)).subtract(1);

    return f;

}
 
Example 2
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    DerivativeStructure sum  = variables[0].getField().getZero().subtract(n + 1);
    DerivativeStructure prod = variables[0].getField().getOne();
  for (int j = 0; j < n; ++j) {
    sum  = sum.add(variables[j]);
    prod = prod.multiply(variables[j]);
  }
  for (int i = 0; i < n; ++i) {
    f[i] = variables[i].add(sum);
  }
  f[n - 1] = prod.subtract(1);
  return f;
}
 
Example 3
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {

    DerivativeStructure[] f = new DerivativeStructure[m];
    Arrays.fill(f, variables[0].getField().getZero());

    for (int j = 0; j < n; ++j) {
        DerivativeStructure tmp1 = variables[0].getField().getOne();
        DerivativeStructure tmp2 = variables[j].multiply(2).subtract(1);
        DerivativeStructure temp = tmp2.multiply(2);
        for (int i = 0; i < m; ++i) {
            f[i] = f[i].add(tmp2);
            DerivativeStructure ti = temp.multiply(tmp2).subtract(tmp1);
            tmp1 = tmp2;
            tmp2 = ti;
        }
    }

    double dx = 1.0 / n;
    boolean iev = false;
    for (int i = 0; i < m; ++i) {
        f[i] = f[i].multiply(dx);
        if (iev) {
            f[i] = f[i].add(1.0 / (i * (i + 2)));
        }
        iev = ! iev;
    }

    return f;

}
 
Example 4
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    for (int i = 0; i < (m - 2); ++i) {
        double div = (i + 1) / 29.0;
        DerivativeStructure s1 = variables[0].getField().getZero();
        DerivativeStructure dx = variables[0].getField().getOne();
        for (int j = 1; j < n; ++j) {
            s1 = s1.add(dx.multiply(j).multiply(variables[j]));
            dx = dx.multiply(div);
        }
        DerivativeStructure s2 = variables[0].getField().getZero();
        dx = variables[0].getField().getOne();
        for (int j = 0; j < n; ++j) {
            s2 = s2.add(dx.multiply(variables[j]));
            dx = dx.multiply(div);
        }
        f[i] = s1.subtract(s2.multiply(s2)).subtract(1);
    }

    DerivativeStructure x1 = variables[0];
    DerivativeStructure x2 = variables[1];
    f[m - 2] = x1;
    f[m - 1] = x2.subtract(x1.multiply(x1)).subtract(1);

    return f;

}
 
Example 5
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    DerivativeStructure sum  = variables[0].getField().getZero().subtract(n + 1);
    DerivativeStructure prod = variables[0].getField().getOne();
  for (int j = 0; j < n; ++j) {
    sum  = sum.add(variables[j]);
    prod = prod.multiply(variables[j]);
  }
  for (int i = 0; i < n; ++i) {
    f[i] = variables[i].add(sum);
  }
  f[n - 1] = prod.subtract(1);
  return f;
}
 
Example 6
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {

    DerivativeStructure[] f = new DerivativeStructure[m];
    Arrays.fill(f, variables[0].getField().getZero());

    for (int j = 0; j < n; ++j) {
        DerivativeStructure tmp1 = variables[0].getField().getOne();
        DerivativeStructure tmp2 = variables[j].multiply(2).subtract(1);
        DerivativeStructure temp = tmp2.multiply(2);
        for (int i = 0; i < m; ++i) {
            f[i] = f[i].add(tmp2);
            DerivativeStructure ti = temp.multiply(tmp2).subtract(tmp1);
            tmp1 = tmp2;
            tmp2 = ti;
        }
    }

    double dx = 1.0 / n;
    boolean iev = false;
    for (int i = 0; i < m; ++i) {
        f[i] = f[i].multiply(dx);
        if (iev) {
            f[i] = f[i].add(1.0 / (i * (i + 2)));
        }
        iev = ! iev;
    }

    return f;

}
 
Example 7
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    for (int i = 0; i < (m - 2); ++i) {
        double div = (i + 1) / 29.0;
        DerivativeStructure s1 = variables[0].getField().getZero();
        DerivativeStructure dx = variables[0].getField().getOne();
        for (int j = 1; j < n; ++j) {
            s1 = s1.add(dx.multiply(j).multiply(variables[j]));
            dx = dx.multiply(div);
        }
        DerivativeStructure s2 = variables[0].getField().getZero();
        dx = variables[0].getField().getOne();
        for (int j = 0; j < n; ++j) {
            s2 = s2.add(dx.multiply(variables[j]));
            dx = dx.multiply(div);
        }
        f[i] = s1.subtract(s2.multiply(s2)).subtract(1);
    }

    DerivativeStructure x1 = variables[0];
    DerivativeStructure x2 = variables[1];
    f[m - 2] = x1;
    f[m - 1] = x2.subtract(x1.multiply(x1)).subtract(1);

    return f;

}
 
Example 8
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    DerivativeStructure sum  = variables[0].getField().getZero().subtract(n + 1);
    DerivativeStructure prod = variables[0].getField().getOne();
  for (int j = 0; j < n; ++j) {
    sum  = sum.add(variables[j]);
    prod = prod.multiply(variables[j]);
  }
  for (int i = 0; i < n; ++i) {
    f[i] = variables[i].add(sum);
  }
  f[n - 1] = prod.subtract(1);
  return f;
}
 
Example 9
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {

    DerivativeStructure[] f = new DerivativeStructure[m];
    Arrays.fill(f, variables[0].getField().getZero());

    for (int j = 0; j < n; ++j) {
        DerivativeStructure tmp1 = variables[0].getField().getOne();
        DerivativeStructure tmp2 = variables[j].multiply(2).subtract(1);
        DerivativeStructure temp = tmp2.multiply(2);
        for (int i = 0; i < m; ++i) {
            f[i] = f[i].add(tmp2);
            DerivativeStructure ti = temp.multiply(tmp2).subtract(tmp1);
            tmp1 = tmp2;
            tmp2 = ti;
        }
    }

    double dx = 1.0 / n;
    boolean iev = false;
    for (int i = 0; i < m; ++i) {
        f[i] = f[i].multiply(dx);
        if (iev) {
            f[i] = f[i].add(1.0 / (i * (i + 2)));
        }
        iev = ! iev;
    }

    return f;

}
 
Example 10
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    for (int i = 0; i < (m - 2); ++i) {
        double div = (i + 1) / 29.0;
        DerivativeStructure s1 = variables[0].getField().getZero();
        DerivativeStructure dx = variables[0].getField().getOne();
        for (int j = 1; j < n; ++j) {
            s1 = s1.add(dx.multiply(j).multiply(variables[j]));
            dx = dx.multiply(div);
        }
        DerivativeStructure s2 = variables[0].getField().getZero();
        dx = variables[0].getField().getOne();
        for (int j = 0; j < n; ++j) {
            s2 = s2.add(dx.multiply(variables[j]));
            dx = dx.multiply(div);
        }
        f[i] = s1.subtract(s2.multiply(s2)).subtract(1);
    }

    DerivativeStructure x1 = variables[0];
    DerivativeStructure x2 = variables[1];
    f[m - 2] = x1;
    f[m - 1] = x2.subtract(x1.multiply(x1)).subtract(1);

    return f;

}
 
Example 11
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    DerivativeStructure sum  = variables[0].getField().getZero().subtract(n + 1);
    DerivativeStructure prod = variables[0].getField().getOne();
  for (int j = 0; j < n; ++j) {
    sum  = sum.add(variables[j]);
    prod = prod.multiply(variables[j]);
  }
  for (int i = 0; i < n; ++i) {
    f[i] = variables[i].add(sum);
  }
  f[n - 1] = prod.subtract(1);
  return f;
}
 
Example 12
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {

    DerivativeStructure[] f = new DerivativeStructure[m];
    Arrays.fill(f, variables[0].getField().getZero());

    for (int j = 0; j < n; ++j) {
        DerivativeStructure tmp1 = variables[0].getField().getOne();
        DerivativeStructure tmp2 = variables[j].multiply(2).subtract(1);
        DerivativeStructure temp = tmp2.multiply(2);
        for (int i = 0; i < m; ++i) {
            f[i] = f[i].add(tmp2);
            DerivativeStructure ti = temp.multiply(tmp2).subtract(tmp1);
            tmp1 = tmp2;
            tmp2 = ti;
        }
    }

    double dx = 1.0 / n;
    boolean iev = false;
    for (int i = 0; i < m; ++i) {
        f[i] = f[i].multiply(dx);
        if (iev) {
            f[i] = f[i].add(1.0 / (i * (i + 2)));
        }
        iev = ! iev;
    }

    return f;

}
 
Example 13
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    for (int i = 0; i < (m - 2); ++i) {
        double div = (i + 1) / 29.0;
        DerivativeStructure s1 = variables[0].getField().getZero();
        DerivativeStructure dx = variables[0].getField().getOne();
        for (int j = 1; j < n; ++j) {
            s1 = s1.add(dx.multiply(j).multiply(variables[j]));
            dx = dx.multiply(div);
        }
        DerivativeStructure s2 = variables[0].getField().getZero();
        dx = variables[0].getField().getOne();
        for (int j = 0; j < n; ++j) {
            s2 = s2.add(dx.multiply(variables[j]));
            dx = dx.multiply(div);
        }
        f[i] = s1.subtract(s2.multiply(s2)).subtract(1);
    }

    DerivativeStructure x1 = variables[0];
    DerivativeStructure x2 = variables[1];
    f[m - 2] = x1;
    f[m - 1] = x2.subtract(x1.multiply(x1)).subtract(1);

    return f;

}
 
Example 14
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    DerivativeStructure sum  = variables[0].getField().getZero().subtract(n + 1);
    DerivativeStructure prod = variables[0].getField().getOne();
  for (int j = 0; j < n; ++j) {
    sum  = sum.add(variables[j]);
    prod = prod.multiply(variables[j]);
  }
  for (int i = 0; i < n; ++i) {
    f[i] = variables[i].add(sum);
  }
  f[n - 1] = prod.subtract(1);
  return f;
}
 
Example 15
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {

    DerivativeStructure[] f = new DerivativeStructure[m];
    Arrays.fill(f, variables[0].getField().getZero());

    for (int j = 0; j < n; ++j) {
        DerivativeStructure tmp1 = variables[0].getField().getOne();
        DerivativeStructure tmp2 = variables[j].multiply(2).subtract(1);
        DerivativeStructure temp = tmp2.multiply(2);
        for (int i = 0; i < m; ++i) {
            f[i] = f[i].add(tmp2);
            DerivativeStructure ti = temp.multiply(tmp2).subtract(tmp1);
            tmp1 = tmp2;
            tmp2 = ti;
        }
    }

    double dx = 1.0 / n;
    boolean iev = false;
    for (int i = 0; i < m; ++i) {
        f[i] = f[i].multiply(dx);
        if (iev) {
            f[i] = f[i].add(1.0 / (i * (i + 2)));
        }
        iev = ! iev;
    }

    return f;

}
 
Example 16
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    for (int i = 0; i < (m - 2); ++i) {
        double div = (i + 1) / 29.0;
        DerivativeStructure s1 = variables[0].getField().getZero();
        DerivativeStructure dx = variables[0].getField().getOne();
        for (int j = 1; j < n; ++j) {
            s1 = s1.add(dx.multiply(j).multiply(variables[j]));
            dx = dx.multiply(div);
        }
        DerivativeStructure s2 = variables[0].getField().getZero();
        dx = variables[0].getField().getOne();
        for (int j = 0; j < n; ++j) {
            s2 = s2.add(dx.multiply(variables[j]));
            dx = dx.multiply(div);
        }
        f[i] = s1.subtract(s2.multiply(s2)).subtract(1);
    }

    DerivativeStructure x1 = variables[0];
    DerivativeStructure x2 = variables[1];
    f[m - 2] = x1;
    f[m - 1] = x2.subtract(x1.multiply(x1)).subtract(1);

    return f;

}
 
Example 17
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
    DerivativeStructure[] f = new DerivativeStructure[m];
    DerivativeStructure sum  = variables[0].getField().getZero().subtract(n + 1);
    DerivativeStructure prod = variables[0].getField().getOne();
  for (int j = 0; j < n; ++j) {
    sum  = sum.add(variables[j]);
    prod = prod.multiply(variables[j]);
  }
  for (int i = 0; i < n; ++i) {
    f[i] = variables[i].add(sum);
  }
  f[n - 1] = prod.subtract(1);
  return f;
}
 
Example 18
Source File: MinpackTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {

    DerivativeStructure[] f = new DerivativeStructure[m];
    Arrays.fill(f, variables[0].getField().getZero());

    for (int j = 0; j < n; ++j) {
        DerivativeStructure tmp1 = variables[0].getField().getOne();
        DerivativeStructure tmp2 = variables[j].multiply(2).subtract(1);
        DerivativeStructure temp = tmp2.multiply(2);
        for (int i = 0; i < m; ++i) {
            f[i] = f[i].add(tmp2);
            DerivativeStructure ti = temp.multiply(tmp2).subtract(tmp1);
            tmp1 = tmp2;
            tmp2 = ti;
        }
    }

    double dx = 1.0 / n;
    boolean iev = false;
    for (int i = 0; i < m; ++i) {
        f[i] = f[i].multiply(dx);
        if (iev) {
            f[i] = f[i].add(1.0 / (i * (i + 2)));
        }
        iev = ! iev;
    }

    return f;

}