我是编程新手,我在尝试使用数组编程多项式的导数时遇到了麻烦。以下是我得到用户输入的内容。
Scanner sc=new Scanner(System.in);
System.out.print("Enter the degree: ");
int degree = sc.nextInt();
System.out.print("Enter "+(degree+1)+" coefficients: ");
double[] C = new double[degree+1];
for(int i=0; i<C.length;i++) {
C[i]=sc.nextDouble();
}
答案 0 :(得分:2)
假设数组C
包含度数降序的n次多项式系数(例如f(x) = C[0]*x^n + ... + C[n-1]*x + C[n]
)
然后D
是你的衍生物数组:
double D[] = new double[C.length-1];
for(int i = 0; i < C.length-1; i++)
D[i] = C[i]*(C.length-i-1);
答案 1 :(得分:0)
假设你的多项式是这样的,
f(x)= C [0] * x ^ n + C [1] * x ^(n-1)....... C [n]
推导后,它变为
f'(x)= C [0] *(n) x ^(n-1)+ C [1] (n-1)* x ^(n- 2)+ ........... + 0 * C [n]
Scanner sc=new Scanner(System.in);
System.out.print("Enter the degree: ");
int degree = sc.nextInt();
System.out.print("Enter "+(degree+1)+" coefficients: ");
double[] C = new double[degree+1];
for(int i=0; i<C.length;i++) {
C[i]=sc.nextDouble();
}
double derivative[] = new double[C.length-1];
for(int i=0;i<derivative.length;i++){
derivative[i] = C[i]*(C.length - 1 -i );
}