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.

DONT use any inbuilt function, instead use looping in Python to solve the question. You should begin the code this way def integral(A, X1, X2):

NO INBUILT functions, I repeat

Solutions

Expert Solution

`Hey,

Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.

import numpy as np
def func(A,x):
y=0;
for i in range(len(A)):
y=y*x+A[i];
return y;
def trapezoidal (a, b, n,A):
# Grid spacing
h = (b - a) / n
  
# Computing sum of first and last terms
# in above formula
s = (func(A,a) + func(A,b))
  
# Adding middle terms in above formula
i = 1
while i < n:
s += 2 * func(A,a + i * h)
i += 1
  
# h/2 indicates (b-a)/2n.
# Multiplying h/2 with s.
return ((h / 2) * s)
def integral(A, X1, X2):
return trapezoidal(X1,X2,100,A);

print(integral(np.array([1,2,3,4]),1,5));

Kindly revert for any queries

Thanks.


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.
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.
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. 2)Write a...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT