Question
Transcribed Text
Solution Preview
These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.
import math # Importing math Python moduleimport numpy as np # Importing numpy module
from scipy.misc import derivative # Importing derivative function from scipy
def Chebyshev1_recur(x, n):
"""
This function evaluates Chebyshev polynomial recursively
:param x: x - value for which chebyshev needs to be evaluated
:param n: n - value for which chebyshev needs to be evaluated
:return: T_n(x) based on the recurrence relation i.e the value of chebyshev polynomial of degree 'n' at 'x'
"""
if n == 0:
# If n = 0 return 1
return 1
elif n == 1:
# If n = 1 return x
return x
else:
# Else return recurrence relation
return 2 * x * Chebyshev1_recur(x, n - 1) - Chebyshev1_recur(x, n - 2)
def chebyshev1(n, start, stop, no_of_steps):
"""
This function calculates the chebyshev function of order 'n' from
'start' till 'stop' for a given number of steps('no_of_steps')
:param n: n - value for which chebyshev needs to be evaluated i.e the order of chebyshev polynomial
:param start: Start value for evaluation of chebyshev polynomial values
:param stop: Stop value for evaluation of chebyshev polynomial values
:param no_of_steps: Number of steps for evaluation of chebyshev polynomial values
:return: A tuple containing points of evaluation of chebyshev and evaluated chebyshev value of order 'n'
"""
# Create an ndarray between start and stop with no_of_steps points using linspace
X = np.linspace(start, stop, no_of_steps)
# Calculate chebyshev on all points for given 'n'
Y = [Chebyshev1_recur(x, n) for x in X]
return X, Y
def weighed_integral_inner_product(x, m, n):
"""
This function calculates the weighed inner product function
:param x: x - value for which weighed inner product needs to be evaluated
:param m: m - value for which weighed inner product needs to be evaluated
:param n: n - value for which weighed inner product needs to be evaluated
:return: Weighed inner product at 'x' for order 'm' and 'n'
"""
# Compute the weighed integral inner product
return (Chebyshev1_recur...
By purchasing this solution you'll be able to access the following files:
assignment.ipynb and assignment.py.