我是编程新手,在尝试使用数组对多项式的导数进行编程时遇到困难。以下是我必须获取用户输入的内容。
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();
}
最佳答案
假设数组 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);
关于java - 在java中使用数组求多项式的导数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21792400/