Question: I need a java program that divides two polynomials. Note that constructors are: /** * Creates a polynomial with the formula of [coefficent]x^[degree] * @param
I need a java program that divides two polynomials. Note that constructors are:
/**
* Creates a polynomial with the formula of "[coefficent]x^[degree]"
* @param degree This is the degree
* @param coefficent This is the coefficient
*/
public Polynomial( int degree, double coefficent )
{
degrees = new int[1];
degrees[0] = degree;
coefficients = new double[1];
coefficients[0] = coefficent;
}
/**
* Creates a 0 polynomial
*/
public Polynomial()
{
coefficients = new double[1];
coefficients[0] = 0;
degrees = new int[1];
degrees[0] = 0;
}
/**
* Creates a polynomial with the coefficients as a given array
* @param coefficients This is the given array for coefficients
*/
public Polynomial( double[] coefficients )
{
this.coefficients = coefficients;
degrees = new int [coefficients.length];
for ( int index = 0; index < degrees.length; index++ )
{
degrees[index] = index;
}
}
div( Polynomial p2 ):
Divides this polynomial with p2 and returns the quotient.
P(x) = 3 + 4x + 1x^2 + 3x^3 + 2x^5
Q(x) = 2 + 1x
For polynomials P(x) and Q(x), the result of the division operation, P(x) / Q(x), is found as follows
: Find the leading term (non zero term with highest degree) of the P(x) and Q(x).
lead(P(x)) = 2x^5
lead(Q(x)) = x
Find polynomial T(x) such that: T(x) = lead(P(x)) / lead(Q(x)) = 2x^4
Subtract T(x) * Q(x) from P(x) and assign the result to P(x).
P(x) Q(x) * T(x) = 3 + 4x + 1x^2 + 3x^3 + -x^4
Add T(x) to the result and repeat this process until the degree of P(x) is higher than the degree of Q(x)
. 2 Result of P(x) / Q(x) is 46 21x + 11x^2 4x^3 + 2x ^4 .
Note that remainder is ignored.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
