Question: def uniform _ poly _ interpolation ( a , b , p , n , x , f , produce _ fig ) : ###
def uniformpolyinterpolationabpnxfproducefig:
### Example of creating a figure object
fig pltfigure # This line is required
#pltplot # Delete this line and replace
#Remove the following line when you have completed the code
#interpolant None
xhat nplinspacea b p
# Call lagrangepoly with tol e
lagrangematrix, errorflag lagrangepolyp xhat, n xe
if errorflag :
printError: Nodal points are not distinct."
return None, None
# Calculate interpolant
interpolant npdotfxhat lagrangematrix
if producefig:
# Plot the function f and the interpolant
fig, ax pltsubplots
axplotx fx labelfx
axplotx interpolant, labelf'Interpolant pp
axlegend
pltshow
else:
fig None
return interpolant, fig
#
def nonuniformpolyinterpolationabpnxfproducefig:
#Remove the following two lines when you have completed the code
#interpolant None
#fig None
xhat npcos nparangep p nppi
# Map nodal points to the interval a b
xhat b a xhat a b
# Call lagrangepoly with tol e
lagrangematrix, errorflag lagrangepolyp xhat, n xe
if errorflag :
printError: Nodal points are not distinct."
return None, None
# Calculate interpolant
interpolant npdotfxhat lagrangematrix
if producefig:
# Plot the function f and the interpolant
fig, ax pltsubplots
axplotx fx labelfx
axplotx interpolant, labelf'Interpolant pp
axlegend
pltshow
else:
fig NonePiecewise Polynomial Interpolation
Recall, given a function : we can construct its piecewise polynomial
interpolant of order by splitting up into uniform subintervals and applying the
Lagrange interpolant of order on each subinterval. Hence, using subintervals
tilde the piecewise interpolant satisfies:
dots,
where is the polynomial interpolant of on tildetilde
In polynomialinterpolation.py you will find a function with definition
def nterpolation
The function should return as output:
puinterpolant, pnuinterpolant two numpy.ndarrays, each of
shape
return interpolant, fig
Need the python code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
