For a first order reaction rate constant , k = ( 2.303 /t )x log ( a / (a-x))
Where
a = initial amount
a-x = amount left after time t = a / 10
t = time = ?
k = rate constant = 3.43x10 -2 d -2
Plug the values we get t = ( 2.303 /k )x log ( a / (a-x))
= ( 2.303 / 3.43x10 -2 )x log ( a / (a/10))
= 67.14 days
Solution
For a first order reaction rate constant , k = ( 2.303 /t )x log ( a / (a-x))
Where
a = initial amount
a-x = amount left after time t = a / 10
t = time = ?
k = rate constant = 3.43x10 -2 d -2
Plug the values we get t = ( 2.303 /k )x log ( a / (a-x))
= ( 2.303 / 3.43x10 -2 )x log ( a / (a/10))
= 67.14 days.
import java.util.Scanner;public class HornersPolynomial { .pdf
1. import java.util.Scanner;
public class HornersPolynomial {
/**
* Calculate the polynomial using Horner's method
* return
*/
public static double hornersMeth(double[] coeff, int n, double x) {
double finalVal = coeff[n];
for(int i = (n - 1) ; i >= 0; i--) {
finalVal = (finalVal * x) + coeff[i];
}
return finalVal;
}
/**
* Prints the polynomial
* param coeff
* param n
* param x
*/
public static void printPoly(double[] coeff, int n, double x) {
System.out.println(" Polynomial : ");
System.out.print(coeff[n] + "x^" + n);
for(int i = (n - 1) ; i >= 0; i--) {
if(coeff[i] < 0)
System.out.print(" - " + ((-1) * coeff[i]) + "x^" + i);
else if(coeff[i] >= 0)
System.out.print(" + " + coeff[i] + "x^" + i);
}
System.out.println(" where x = " + x);
}
2. public static void main(String[] args) {
//Scanner for user input
Scanner sc = new Scanner(System.in);
//Get degree of the polynomial
System.out.println(" Enter the degree of the polynomial: ");
int n = sc.nextInt();
//Coefficicnets array
double[] coeff = new double[n + 1];
for(int i = n ; i >= 0; i--) {
System.out.println("Enter coefficient " + i + ": ");
coeff[i] = sc.nextDouble();
}
//Get value of x
System.out.println(" Enter the value of x: ");
double x = sc.nextDouble();
printPoly(coeff, n, x);
System.out.println(" Value of the polynomila is " + hornersMeth(coeff, n, x));
//Close scanner
sc.close();
}
}
SAMPLE OUTPUT:
Enter the degree of the polynomial:
3
Enter coefficient 3:
2
Enter coefficient 2:
-6
Enter coefficient 1:
2
3. Enter coefficient 0:
-1
Enter the value of x:
3
Polynomial :
2.0x^3 - 6.0x^2 + 2.0x^1 - 1.0x^0
where x = 3.0
Value of the polynomila is 5.0
Solution
import java.util.Scanner;
public class HornersPolynomial {
/**
* Calculate the polynomial using Horner's method
* return
*/
public static double hornersMeth(double[] coeff, int n, double x) {
double finalVal = coeff[n];
for(int i = (n - 1) ; i >= 0; i--) {
finalVal = (finalVal * x) + coeff[i];
}
return finalVal;
}
/**
* Prints the polynomial
* param coeff
* param n
* param x
*/
public static void printPoly(double[] coeff, int n, double x) {
System.out.println(" Polynomial : ");
System.out.print(coeff[n] + "x^" + n);
4. for(int i = (n - 1) ; i >= 0; i--) {
if(coeff[i] < 0)
System.out.print(" - " + ((-1) * coeff[i]) + "x^" + i);
else if(coeff[i] >= 0)
System.out.print(" + " + coeff[i] + "x^" + i);
}
System.out.println(" where x = " + x);
}
public static void main(String[] args) {
//Scanner for user input
Scanner sc = new Scanner(System.in);
//Get degree of the polynomial
System.out.println(" Enter the degree of the polynomial: ");
int n = sc.nextInt();
//Coefficicnets array
double[] coeff = new double[n + 1];
for(int i = n ; i >= 0; i--) {
System.out.println("Enter coefficient " + i + ": ");
coeff[i] = sc.nextDouble();
}
//Get value of x
System.out.println(" Enter the value of x: ");
double x = sc.nextDouble();
printPoly(coeff, n, x);
System.out.println(" Value of the polynomila is " + hornersMeth(coeff, n, x));
//Close scanner
sc.close();
}
}
5. SAMPLE OUTPUT:
Enter the degree of the polynomial:
3
Enter coefficient 3:
2
Enter coefficient 2:
-6
Enter coefficient 1:
2
Enter coefficient 0:
-1
Enter the value of x:
3
Polynomial :
2.0x^3 - 6.0x^2 + 2.0x^1 - 1.0x^0
where x = 3.0
Value of the polynomila is 5.0