I am new to programming and I have trouble trying to program the derivative of a polynomial using arrays. Below is what I have to get the user's input.
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();
}
Let's assume that the array C
contains the coefficients of an n-th degree polynomial in descending order of degree (e.g. for f(x) = C[0]*x^n + ... + C[n-1]*x + C[n]
)
Then D
is your array of derivatives:
double D[] = new double[C.length-1];
for(int i = 0; i < C.length-1; i++)
D[i] = C[i]*(C.length-i-1);