Question

In: Computer Science

Let P(x) be a polynomial of degree n and A = [an , an-1,.... ] Write...

Let P(x) be a polynomial of degree n

and A = [an , an-1,.... ]

Write a function integral(A, X1, X2) that takes 3 inputs A, X0 and X1

A as stated above

X1 and X2 be any real number, where X1 is the lower limit of the integral and X2 is the upper limit of the integral. Please write this code in Python.

Solutions

Expert Solution

Python program for the provided problem statement

# import library
from scipy.integrate import quad

def integrand(x,A):
size = len(A)
s = 0
for i in range(size):
s += A[i]*x**(size-i-1)
  
return s

# this will calculate integral value
def integral(A, x1, x2):
ans, err = quad(integrand, x1, x2, args=A)
# display final result
print("\nIntegration of Polynomial :=> ",ans)
  
# list for coefficients
A = []   
A = [int(item) for item in input("Enter coefficients of polynomial [an, an-1....a0]: ").split()]

# display polinomial
s = ""
for i in range(len(A)):
s += (str)(A[i])+"*x^"+(str)(len(A)-i-1)
if i != len(A)-1:
s += " + "

# input limits
print("\nPolynomial :=> ",s)
x1 = int(input("\nEnter lower limit: "))
x2 = int(input("Enter upper limit: "))
integral(A, x1, x2)

Code Screenshot

program output 1 screenshot

program output 2 screenshot


Related Solutions

Let P(x) be a polynomial of degree n and A = [an , an-1,.... ] Write...
Let P(x) be a polynomial of degree n and A = [an , an-1,.... ] Write a function integral(A, X1, X2) that takes 3 inputs A, X0 and X1 A as stated above X1 and X2 be any real number, where X1 is the lower limit of the integral and X2 is the upper limit of the integral. Please write this code in Python. DONT use any inbuilt function, instead use looping in Python to solve the question. You should...
Prove the following: Let f(x) be a polynomial in R[x] of positive degree n. 1. The...
Prove the following: Let f(x) be a polynomial in R[x] of positive degree n. 1. The polynomial f(x) factors in R[x] as the product of polynomials of degree 1 or 2. 2. The polynomial f(x) has n roots in C (counting multiplicity). In particular, there are non-negative integers r and s satisfying r+2s = n such that f(x) has r real roots and s pairs of non-real conjugate complex numbers as roots. 3. The polynomial f(x) factors in C[x] as...
Let x0< x1< x2. Show that there is a unique polynomial P(x) of degree at most...
Let x0< x1< x2. Show that there is a unique polynomial P(x) of degree at most 3 such that P(xj) =f(xj) j= 0,1,2, and P′(x1) =f′(x1) Give an explicit formula for P(x). maybe this is a Hint using the Hermit Polynomial: P(x) = a0 +a1(x-x0)+a2(x-x0)^2+a3(x-x0)^2(x-x1)
If p(z) is a polynomial of degree n and that if α is a root of...
If p(z) is a polynomial of degree n and that if α is a root of p(z) = 0, then p(z) factors as p(z) = (z−α)q(z) where q(z) has degree (n − 1). Use this and induction to show that a polynomial of degree n has at most n roots.
Use induction to prove Let f(x) be a polynomial of degree n in Pn(R). Prove that...
Use induction to prove Let f(x) be a polynomial of degree n in Pn(R). Prove that for any g(x)∈Pn(R) there exist scalars c0, c1, ...., cn such that g(x)=c0f(x)+c1f′(x)+c2f′′(x)+⋯+cnf(n)(x), where f(n)(x)denotes the nth derivative of f(x).
Let f be an irreducible polynomial of degree n over K, and let Σ be the...
Let f be an irreducible polynomial of degree n over K, and let Σ be the splitting field for f over K. Show that [Σ : K] divides n!.
Given: Polynomial P(x) of degree 6 Given: x=3 is a zero for the Polynomial above List...
Given: Polynomial P(x) of degree 6 Given: x=3 is a zero for the Polynomial above List all combinations of real and complex zeros, but do not consider multiplicity for the zeros.
Using C++ 1) Write a program that repeatedly evaluates a n-th order polynomial p(x) = a0...
Using C++ 1) Write a program that repeatedly evaluates a n-th order polynomial p(x) = a0 + a1*x + a2*x^2 + ... + an*x^n where n <= 10 The program inputs n, ai, and x from the keyboard and then prints out the corresponding value of p to the screen. The program continues to input new values of n, ai, x and evaluates p until a negative value for n is input, at which point the program stops.
Given n ∈N and p prime number and consider the polynomial f (x) = xn (xn-2)+1-p...
Given n ∈N and p prime number and consider the polynomial f (x) = xn (xn-2)+1-p 1)Prove that f (x) is irreducible in Q [x] 2) If n = 1 and p = 3, find Q [x] / f (x)) 3) Show that indeed Q [x] / (f (x)) is a field in the previous paragraph PLEASE answer all subsections
Polynomial Multiplication by Divide-&-Conquer A degree n-1 polynomial ? (?) =Σ(n-1)(i=0) ???i = ?0 + ?1?...
Polynomial Multiplication by Divide-&-Conquer A degree n-1 polynomial ? (?) =Σ(n-1)(i=0) ???i = ?0 + ?1? + ?2?2 ... + ??−1?n-1 can be represented by an array ?[0. . ? − 1] of its n coefficients. Suppose P(x) and Q(x) are two polynomials of degree n-1, each given by its coefficient array representation. Their product P(x)Q(x) is a polynomial of degree 2(n-1), and hence can be represented by its coefficient array of length 2n-1. The polynomial multiplication problem is to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT