Question

In: Computer Science

introduction A univariate polynomial (i.e. a polynomial of one variable) is defined as the sum of...

introduction
A univariate polynomial (i.e. a polynomial of one variable) is defined as the sum of terms of the form axb
where a is a real coefficient, x is a variable, and b ≥ 0 is an integer exponent. Therefore, the following
mathematical expressions are univariate polynomials.
4.5x^3 – 2.1x^2 + 6.2x – 9.7
-8.3x^4 + 7.6x
2.0x^2
0
The degree of a polynomial is defined as its highest-valued exponent. Hence, the degrees of the four
polynomials above are 3, 4, 2 and 0, respectively. Note as well that the terms of each polynomial are
sorted by decreasing exponent values.
The following mathematical expressions are not univariate polynomials. The first has a negative exponent
and the second is expressed in terms of two variables, x and y.
x^2 + x – x ^-2
9.4xy
For this assignment, each pair or trio of programmers is expected to create, manipulate, and output a
collection of polynomials via a menu-driven user interface.

Task 5: Main Program

The class Program includes the static Main method which serves as the entry point of execution.

class Program

{

static void Main (string[] args)

{

Polynomial S; // Collection of polynomials

}

}

The main program provides the user interface to manipulates the collection S of polynomials, namely:

1) To create a polynomial and insert it into S (no index is needed),

2) To add two polynomials from S (retrieved by index) and to insert the resultant polynomial into S,

3) To multiply two polynomials from S (retrieved by index) and to insert the resultant polynomial into S,

4) To delete the polynomial from S at a given index, and

5) To evaluate the polynomial from S at a given index.

To aid the user, the collection of polynomials is output before each operation. The polynomials are numbered (indexed) starting at 0.

Indices should be checked before an add, multiply, delete or evaluate is performed.

Please use C# to answer this question!!!

Solutions

Expert Solution

class Polynomial: IComparable
{
        double[] Coefficents;

        public Polynomial(double[] coeffs)
        {
                Init(coeffs);
        }

        public void Init(double[] coeffs)
        {
                Coefficents = coeffs;
        }

        public int GetDegree()
        {
                return Coefficients.Length - 1;
        }

        public double evaluate(double x)
        {
                double y = 0;
                double px = 1;
                for (int i = 0; i < Coefficients.Length; i++)
                {
                        y += px * Coefficients[i];
                        px *= x;
                }
                return y;
        }

        // Create a string representation
        public override string ToString()
        {
                string result;
                if (Coefficients.Length)
                        result = Double.ToString(Coefficients[0]);
                for (int i = 1; i < Coefficients.Length; i++)
                {
                        if (Coefficients[i] < 0)
                                result += " - ";
                        else
                                result += " + ";
                        result += Double.ToString(Math.Abs(Coefficients[i]));
                        result += "*x^";
                        result += Int.ToString(i);
                }
                return result;
        }
        // A[] represents coefficients of first polynomial
        // B[] represents coefficients of second polynomial
        // m and n are sizes of A[] and B[] respectively
        static int[] add(int[] A, int[] B, int m, int n)
        {
                int size = max(m, n);
                int[] sum = new int[size];

                // Initialize the porduct polynomial
                for (int i = 0; i < m; i++)
                {
                        sum[i] = A[i];
                }

                // Take ever term of first polynomial
                for (int i = 0; i < n; i++)
                {
                        sum[i] += B[i];
                }

                return sum;
        }

        static int[] multiply(int []A, int []B,
                              int m, int n)
        {
                int[] prod = new int[m + n - 1];

                // Initialize the porduct polynomial
                for (int i = 0; i < m + n - 1; i++)
                {
                        prod[i] = 0;
                }

                // Multiply two polynomials term by term
                // Take ever term of first polynomial
                for (int i = 0; i < m; i++)
                {
                        // Multiply the current term of first polynomial
                        // with every term of second polynomial.
                        for (int j = 0; j < n; j++)
                        {
                                prod[i + j] += A[i] * B[j];
                        }
                }

                return prod;
        }

}

Related Solutions

Prove that the partition problem is NP-complete by giving a polynomial time reduction of the subset-sum...
Prove that the partition problem is NP-complete by giving a polynomial time reduction of the subset-sum problem to the partition problem.
Very briefly, give a short no more than one-page (per subject) tutorial (i.e., introduction and problem...
Very briefly, give a short no more than one-page (per subject) tutorial (i.e., introduction and problem statement, state-of-the-art, and recent advances) on NO MORE THAN 3 (any three) of the following topics. Topics: i) Bio-inspired Mechatronic Systems ii) Mechatronic Systems for Rehabilitation iii) Micro and Nano Mechatronic Systems iv) Mechatronic Systems for Energy Harvesting, Transfer and Storage v) Social Mechatronic Systems vi) Mechatronic Systems for Advanced Manufacturing
2. One‐Sample Univariate Hypothesis Testing with Proportions For this question, show the results “by hand”, but...
2. One‐Sample Univariate Hypothesis Testing with Proportions For this question, show the results “by hand”, but you can use R to check your work. Suppose that the 4‐year graduation rate at a large, public university is 70 percent (this is the population proportion of successes). In an effort to increase graduation rates, the university randomly selected 200 incoming freshman to participate in a peer‐advising program. After 4 years, 154 of these students graduated. What are the null and alternative hypotheses?...
Use quantifiers, predicates, and relations (i.e., predicates with more than one variable) to symbolize the statements....
Use quantifiers, predicates, and relations (i.e., predicates with more than one variable) to symbolize the statements. Let the domain of discourse be all students in this class. Let R ( x, y ) = x reads y, P ( x, y ) = x plays y, V ( x, y ) = x visited y, L ( x, y ) = x learned foreign language y, T ( x, y ) = x has taken y, C ( x, y...
Is trade a zero sum game, i.e. are there any losers to increased liberalization?
Is trade a zero sum game, i.e. are there any losers to increased liberalization?
a.A method that accepts no parameters and returns the length of the name, i.e., the sum...
a.A method that accepts no parameters and returns the length of the name, i.e., the sum of the lengths of the three parts of the name. b.A method that accepts no parameters and returns a String consisting of the three initials IN UPPERCASE. c.A method that accepts an integer n and returns the nth character in the full three part name. d.A method that accepts no parameters and returns a String consisting of the last name followed by a comma...
Introduction: Objectives, defined as results that can be achieved should be crafted in a way that...
Introduction: Objectives, defined as results that can be achieved should be crafted in a way that each goal is strategic, tactical, and operational. The environmental objectives need to fit within the larger goals of the organizations EMS policy, so while defining objectives below is a useful practice, they should be reconsidered within the broader context of the organization when possible. Successful and well defined goals or objectives should be supported by measurable and concrete indicators, should be used to gain...
Let T : Pn → R be defined by T(p(x)) = the sum of all the...
Let T : Pn → R be defined by T(p(x)) = the sum of all the the coefficients of p(x). Show that T is a linear transformation with dim(ker T) = n and conclude that {x − 1, x2 − 1, . . . , x^n − 1} is a basis of ker T.
1. One‐Sample Univariate Hypothesis Testing of a Mean Consider a random sample of 5 adults over...
1. One‐Sample Univariate Hypothesis Testing of a Mean Consider a random sample of 5 adults over the age of 25 from a large population, which is normally distributed, where E represents the total years of education completed: ? = [10, 12, 12, 16, 16] Suppose that someone claims that the average person in the population is a college graduate (? = 16). A. What is the null hypothesis?  What is the alternative hypothesis? B. Can you reject the null hypothesis at...
Does every polynomial equation have at least one real root? a. Why must every polynomial equation...
Does every polynomial equation have at least one real root? a. Why must every polynomial equation of degree 3 have at least one real root? b. Provide an example of a polynomial of degree 3 with three real roots. How did you find this? c. Provide an example of a polynomial of degree 3 with only one real root. How did you find this?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT