Question: In the python file Pmath 0 4 b . py , 2 D bicubic interpolation is done with the assumption that both x and y
In the python file
Pmathbpy bicubic interpolation is done with the assumption that both and are
The code does not work if the unknown point is outside the domain. Please write a bicubic
interpolation function without using derivatives similar to the function myinterpbilin in this file.
That is the user can specify the and vectors with the corresponding And the function value of the
new point can be found if is within the specified domain.
Pmathbpy :
# coding: utf
dimensional interpolation. Based on the book:Numerical methods for engineers, th by Chapra
page
import numpy as np
from scipy import interpolate as interp #interpolate import interpd
x nparange
y nparange
xx yy npmeshgridx y
z npsinxxyy #based on length of x y construct matrix z size: lenx by leny
# finterp interp.interpdx y z kind'cubic'
finterpL interp.interpdx y z kind'linear'
printUse scipy interpolate interpd function, linearly interpolated value finterpL
def fX:
xX; yX;
#return npsinxnpsinx npsinxnpcosy#xx xy yy
return xy #npsinnpsqrtx y
# xpoint
# printffxpoint
def myinterpbilinptvalVpX:#p is the new point; X contains the coord of xy and xy
#V contains f values at xyxyxyxythe corners
xp; yp; # x and y coordinate of the new point
pX; pX;
xp; yp;
xp; yp;
fV; fV;
fV; fV;
denxxyy;
fxxyyfden #xxyy
ffxxyyfden#xxyy
ffxxyyfden#xxyy
ffxxyyfden#xxyy
#printxyxyxyxy
return f
printExample from the book by Chapra. Function values at points are known:
printf; f; f; f;
newp
V
Xcoord
printAt the point',newp, fmyinterpbilinptvalVnewp,Xcoord
def myinterpbilinxyzp:#p is the new point; x and y are grid points; zfxy
xnp; ynp
if xnx or yny:
printOut of range!
return
else:
for i in rangelenx:#find the x position of the new point
if xixn:
indxi
break
for i in rangeleny:#find the y position of the new point
if yiyn:
indyi
break
xxindx; xxindx;
yyindy; yyindy;
fzindxindy;
fzindxindy;
fzindxindy;
fzindxindy;
denxxyy;
fxnxynyfden #xxyy
ffxnxynyfden#xxyy
ffxnxynyfden#xxyy
ffxnxynyfden#xxyy
#printxyxyxyxy
return f
printUse myinterpbilin:myinterpbilinxyz
# xmat#the st row is xy The nd row is xy
# xnew
# printffmyinterpbilinfxnew, xmat
def mydotab:
nalena
nblenb
f
if nanb:
printError The two input vectors should have the same length.
else:
for i in rangena:
ffaibi
return f
def pxy: # pxy sigmai sigmaj xi yj
n
cnpzerosnn
for i in rangen:
for j in rangen:
cij cij yj
cicixi
return c
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
