All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.accelad.math.nilgiri.autodiff.PolynomialTerm Maven / Gradle / Ivy

There is a newer version: 1.16
Show newest version
package com.accelad.math.nilgiri.autodiff;

import java.util.List;

import com.accelad.math.nilgiri.Field;

public class PolynomialTerm> extends AbstractUnaryFunction {

    protected long m_scale;
    protected int m_exponent;

    public PolynomialTerm(long i_scale, DifferentialFunction i_v, int i_exponent) {
        // scale v^{exponent}
        super(i_v);
        m_scale = i_scale;
        m_exponent = i_exponent;
    }

    @Override
    public X getValue() {
        return (arg().getValue().pow(m_exponent)).mul(m_scale);
    }

    @Override
    public double getReal() {
        return Math.pow(arg().getReal(), m_exponent) * m_scale;
    }

    @Override
    public DifferentialFunction diff(Variable i_v) {
        return (new PolynomialTerm(m_scale * m_exponent, arg(), m_exponent - 1))
                .mul(arg().diff(i_v));
    }

    @Override
    public String toString() {
        return m_scale + arg().toString() + "^" + m_exponent;
    }

    @Override
    public String getFormula(List> variables) {
        return "( " + m_scale + " * Math.pow(" + arg().getFormula(variables) + "," + m_exponent
                + ")";
    }

    @Override
    public DifferentialFunction inverse() {
        return new PolynomialTerm(m_scale, arg(), -m_exponent);
    }

    @Override
    public DifferentialFunction negate() {
        return new PolynomialTerm(-m_scale, arg(), m_exponent);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy