用java求函数的一阶倒数及偏导

用java求函数的一阶倒数及偏导,第1张

java求函数的一阶导数及偏导
//求函数的一阶导数,及一阶偏导
public class Test4 {
    private static final double DELTA = 0.00000000000000000001;
    public static void main(String[] args) {
        DerivedFunction derivedFunction = new DerivedFunction(new Function());
        System.out.println(derivedFunction.get(2));
        System.out.println(derivedFunction.getY(2, 2));
    }

    public static class DerivedFunction {
        //待求导的函数
        public Function function;
        public DerivedFunction(Function function) {
            this.function =function;
        }
        public  double get(double x) {
            return (Function.f(x + DELTA) - Function.f(x)) /DELTA;
        }
        public double getX(double x,double y){

            return (Function.f1(x+DELTA,y) - Function.f1(x,y)) /DELTA;
        }
        public double getY(double x,double y){

            return (Function.f1(x,y+DELTA) - Function.f1(x,y)) /DELTA;
        }
    }
    public static class Function {
        public Double x;
        public Double y;
        public static double f(double x) {
            return x*x;
        }
        public static double f1(double x,double y){
            return x*x+y*y*y;
        }
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/741210.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-28
下一篇 2022-04-28

发表评论

登录后才能评论

评论列表(0条)

保存