SlideShare ist ein Scribd-Unternehmen logo
1 von 2
Downloaden Sie, um offline zu lesen
#%% Q4 code
def poly_interpolation_2d(p,a,b,c,d,X,Y,n,m,f,produce_fig):
#Remove the following two lines when you have completed the code
interpolant = None
fig = None
return interpolant,fig
#%% Q4 Test
################
f = lambda x,y : np.exp(x**2+y**2)
n = 4; m = 3
a = 0; b = 1; c = -1; d = 1
x = np.linspace(a,b,n)
y = np.linspace(c,d,m)
X,Y = np.meshgrid(x,y)
interpolant,fig = poly_interpolation_2d(11,a,b,c,d,X,Y,n,m,f,False)
print("n################################")
print('Q4 TEST OUTPUT:n')
print("interpolant = n")
print(interpolant)
################
using python Interpolation of Multivariate functions Lagrange interpolation can also be used for
interpolation of multivariate functions. Suppose we have a function f:R2R that we would like to
approximate over the rectangular region [a,b][c,d]. To interpolate with a polynomial of degree p,
we can define a set of p+1 distinct nodal points in both the x and y directions: {x^i}i=0p and
{y^i}i=0p, respectively. f can then be interpolated by the function
pp(x,y)=i=0pj=0pf(x^i,y^j)Lx,i(x)Ly,j(y), where {Lx,i(x)}i=0p are the Lagrange polynomials
associated with x nodal points and {Ly,j(y)}j=0p are the Lagrange polynomials associated with
the y nodal points. 4 In approximations . py you will find a function with the following
definition: def poly_interpolation_2d (p,a,b, ,d,X,Y,n,m,f, produce_fig) The function should
return as output: - interpolant - a numpy . ndarray of shape (m,n); - fig - a
matplotlib.figure.Figure when the Boolean input produce_fig is True and None if produce_fig is
False. - Complete the function so that it evaluates the p th order polynomial pp(x,y) of a function
at a set of grid points stored in the mn arrays X and Y. Here, X and Y are assumed to have been
created using the numpy .meshgrid function. Hence, the ij th component of interpolant should
contain the value of pp(Xij,Yij). The nodal interpolating points in x and y should be uniformly
spaced over the intervals [a,b] and [c,d] respectively, including the endpoints. - The function
must call lagrange_poly from Q1 with tol =1.0e10. - If produce_fig is True then the function
should produce a contour plot of the interpolant pp(x,y), which is returned in fig. - Once you
have written poly_interpolation_2d test it by running approximations. py. You should obtain:
interpolant
=[[2.718281833.037731784.239496217.3890561][0.999999931.117518991.559623392.7182816
4][2.718281833.037731784.239496217.3890561]

Weitere ähnliche Inhalte

Ähnlich wie # Q4 code def poly_interpolation_2d(p,a,b,c,d,X,Y,n,m,f,produce_.pdf

MAT-121 COLLEGE ALGEBRAWritten Assignment 32 points eac.docx
MAT-121 COLLEGE ALGEBRAWritten Assignment 32 points eac.docxMAT-121 COLLEGE ALGEBRAWritten Assignment 32 points eac.docx
MAT-121 COLLEGE ALGEBRAWritten Assignment 32 points eac.docx
jessiehampson
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
Amit Kapoor
 
Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdfUse C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdf
admin447081
 

Ähnlich wie # Q4 code def poly_interpolation_2d(p,a,b,c,d,X,Y,n,m,f,produce_.pdf (18)

MAT-121 COLLEGE ALGEBRAWritten Assignment 32 points eac.docx
MAT-121 COLLEGE ALGEBRAWritten Assignment 32 points eac.docxMAT-121 COLLEGE ALGEBRAWritten Assignment 32 points eac.docx
MAT-121 COLLEGE ALGEBRAWritten Assignment 32 points eac.docx
 
Lagrange Interpolation
Lagrange InterpolationLagrange Interpolation
Lagrange Interpolation
 
Kristhyan kurtlazartezubia evidencia1-metodosnumericos
Kristhyan kurtlazartezubia evidencia1-metodosnumericosKristhyan kurtlazartezubia evidencia1-metodosnumericos
Kristhyan kurtlazartezubia evidencia1-metodosnumericos
 
Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report
 
A brief introduction to apply functions
A brief introduction to apply functionsA brief introduction to apply functions
A brief introduction to apply functions
 
Introduction to Tensorflow
Introduction to TensorflowIntroduction to Tensorflow
Introduction to Tensorflow
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
Math 116 pres. 5
Math 116 pres. 5Math 116 pres. 5
Math 116 pres. 5
 
Mechanical Engineering Homework Help
Mechanical Engineering Homework HelpMechanical Engineering Homework Help
Mechanical Engineering Homework Help
 
CONSIDER THE INTERVAL [0, ). FOR EACH NUMERICAL VALUE BELOW, IS IT IN THE INT...
CONSIDER THE INTERVAL [0, ). FOR EACH NUMERICAL VALUE BELOW, IS IT IN THE INT...CONSIDER THE INTERVAL [0, ). FOR EACH NUMERICAL VALUE BELOW, IS IT IN THE INT...
CONSIDER THE INTERVAL [0, ). FOR EACH NUMERICAL VALUE BELOW, IS IT IN THE INT...
 
Matlab practice
Matlab practiceMatlab practice
Matlab practice
 
Python High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptPython High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.ppt
 
Python Programming
Python Programming Python Programming
Python Programming
 
Funções 4
Funções 4Funções 4
Funções 4
 
Matlab project
Matlab projectMatlab project
Matlab project
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)
 
ML with python.pdf
ML with python.pdfML with python.pdf
ML with python.pdf
 
Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdfUse C++ for all  1 bool mapContainsKeysarrayltintgt nu.pdf
Use C++ for all 1 bool mapContainsKeysarrayltintgt nu.pdf
 

Mehr von alstradecentreerode

(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdf(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdf
alstradecentreerode
 
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
alstradecentreerode
 
#define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf
#define LOGFILE signal_log.txt  Signal handlers void sigusr1.pdf#define LOGFILE signal_log.txt  Signal handlers void sigusr1.pdf
#define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf
alstradecentreerode
 
�Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
 �Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf �Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
�Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
alstradecentreerode
 

Mehr von alstradecentreerode (20)

(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdf(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdf
 
(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf
(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf
(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf
 
(if any) is your opportunity cost.pdf
(if any) is your opportunity cost.pdf(if any) is your opportunity cost.pdf
(if any) is your opportunity cost.pdf
 
(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf
(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf
(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf
 
(Elementary Statistics) Computer=1100(102r+1).pdf
(Elementary Statistics) Computer=1100(102r+1).pdf(Elementary Statistics) Computer=1100(102r+1).pdf
(Elementary Statistics) Computer=1100(102r+1).pdf
 
(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf
(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf
(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf
 
(d) Give a single line of R code that will produce a plot exactly li.pdf
(d) Give a single line of R code that will produce a plot exactly li.pdf(d) Give a single line of R code that will produce a plot exactly li.pdf
(d) Give a single line of R code that will produce a plot exactly li.pdf
 
(5 points) There are seven boys and six girls. Coach wants to select.pdf
(5 points) There are seven boys and six girls. Coach wants to select.pdf(5 points) There are seven boys and six girls. Coach wants to select.pdf
(5 points) There are seven boys and six girls. Coach wants to select.pdf
 
(2ab)5.pdf
(2ab)5.pdf(2ab)5.pdf
(2ab)5.pdf
 
(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf
(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf
(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf
 
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
 
(10 points) Construct a BST by inserting the following keys into an .pdf
(10 points) Construct a BST by inserting the following keys into an .pdf(10 points) Construct a BST by inserting the following keys into an .pdf
(10 points) Construct a BST by inserting the following keys into an .pdf
 
#2 Listed below are the numbers of triplets born in a country each y.pdf
#2 Listed below are the numbers of triplets born in a country each y.pdf#2 Listed below are the numbers of triplets born in a country each y.pdf
#2 Listed below are the numbers of triplets born in a country each y.pdf
 
#52 In a large American university in 1969, the male and female pro.pdf
#52 In a large American university in 1969, the male and female pro.pdf#52 In a large American university in 1969, the male and female pro.pdf
#52 In a large American university in 1969, the male and female pro.pdf
 
#define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf
#define LOGFILE signal_log.txt  Signal handlers void sigusr1.pdf#define LOGFILE signal_log.txt  Signal handlers void sigusr1.pdf
#define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf
 
�Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf
 �Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf �Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf
�Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf
 
�derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf
 �derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf �derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf
�derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf
 
�Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf
 �Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf �Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf
�Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf
 
�Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
 �Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf �Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
�Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
 
�Cu�l de los siguientes se considera un indicador principal de la e.pdf
 �Cu�l de los siguientes se considera un indicador principal de la e.pdf �Cu�l de los siguientes se considera un indicador principal de la e.pdf
�Cu�l de los siguientes se considera un indicador principal de la e.pdf
 

Kürzlich hochgeladen

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 

# Q4 code def poly_interpolation_2d(p,a,b,c,d,X,Y,n,m,f,produce_.pdf

  • 1. #%% Q4 code def poly_interpolation_2d(p,a,b,c,d,X,Y,n,m,f,produce_fig): #Remove the following two lines when you have completed the code interpolant = None fig = None return interpolant,fig #%% Q4 Test ################ f = lambda x,y : np.exp(x**2+y**2) n = 4; m = 3 a = 0; b = 1; c = -1; d = 1 x = np.linspace(a,b,n) y = np.linspace(c,d,m) X,Y = np.meshgrid(x,y) interpolant,fig = poly_interpolation_2d(11,a,b,c,d,X,Y,n,m,f,False) print("n################################") print('Q4 TEST OUTPUT:n') print("interpolant = n") print(interpolant) ################ using python Interpolation of Multivariate functions Lagrange interpolation can also be used for interpolation of multivariate functions. Suppose we have a function f:R2R that we would like to approximate over the rectangular region [a,b][c,d]. To interpolate with a polynomial of degree p, we can define a set of p+1 distinct nodal points in both the x and y directions: {x^i}i=0p and {y^i}i=0p, respectively. f can then be interpolated by the function pp(x,y)=i=0pj=0pf(x^i,y^j)Lx,i(x)Ly,j(y), where {Lx,i(x)}i=0p are the Lagrange polynomials associated with x nodal points and {Ly,j(y)}j=0p are the Lagrange polynomials associated with the y nodal points. 4 In approximations . py you will find a function with the following definition: def poly_interpolation_2d (p,a,b, ,d,X,Y,n,m,f, produce_fig) The function should return as output: - interpolant - a numpy . ndarray of shape (m,n); - fig - a matplotlib.figure.Figure when the Boolean input produce_fig is True and None if produce_fig is False. - Complete the function so that it evaluates the p th order polynomial pp(x,y) of a function
  • 2. at a set of grid points stored in the mn arrays X and Y. Here, X and Y are assumed to have been created using the numpy .meshgrid function. Hence, the ij th component of interpolant should contain the value of pp(Xij,Yij). The nodal interpolating points in x and y should be uniformly spaced over the intervals [a,b] and [c,d] respectively, including the endpoints. - The function must call lagrange_poly from Q1 with tol =1.0e10. - If produce_fig is True then the function should produce a contour plot of the interpolant pp(x,y), which is returned in fig. - Once you have written poly_interpolation_2d test it by running approximations. py. You should obtain: interpolant =[[2.718281833.037731784.239496217.3890561][0.999999931.117518991.559623392.7182816 4][2.718281833.037731784.239496217.3890561]