Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DU 1 4 klasse Lagrange _ Polynomial: def init ( self , data _ x , data _ y ) : ' ' ' Earst

DU14
"klasse Lagrange_Polynomial:
def init(self, data_x, data_y):
'''
Earst moatte wy kontrolearje oft de ynfiervektoren (numpy arrays) gelyk binne
of net.
assert (betingst),""msg""
dit kommando kontrolearret as de betingst wier of falsk is. As wier, de koade
rint normaal. Mar as falsk, dan jout de koade in flaterberjocht ""msg""
en stopet tfiering
'''
assert len(data_x)== len(data_y),""lingte fan data_x en data_y moatte gelyk wze""
'''
Lagrange polynomen brke gjin coefficeints a_i, leaver de knopen
(x_i, y_i). Drom moatte wy dizze gewoan yn it objekt opslaan
'''
self.data_x = data_x
self.data_y = data_y
self.degree = len(data_x)-1
# wy geane derfan t dat de yngongen binne numpy array, dus wy kinne tfiere
# elemint wize operaasjes
def repr(sels):
# metoade foar tekenrige fertsjintwurdiging
# jo hoege jo gjin soargen te meitsjen oer de folgjende koade as jo it net begripe
strL = f""LagrangePolynomial of order {self.degree}
""
strL +=""p(x)=""
for i in range(len(self.data_y)):
as self.data_y[i]==0:
trochgean
elif self.data_y[i]>=0:
strL += f""+{self.data_y[i]}*l_{i}(x)""
oars:
strL += f""-{-self.data_y[i]}*l_{i}(x)""
werom strL
def l(sels, k, x):
'''
Dizze metoade ymplementearret de Lagrange Basis foar ynterpolaasje
mei help fan Lagrange Polynomials.
'''
l_k =1.0 # Inisjalisaasje
# --------------------------------------------
# JIN KODE HJIR
#raise NotImplementedError()
#
# HINT FOAR LOOP METHODE: Soe der tsjen moatte
# x_k = self.data_x[k]
# foar j yn berik(self.degree +1):
# l_k *=?????
#
# TIP FOAR VEKTORISEERDE METODE (gjin lussen):
# Google hoe't jo np.prod en np.delete brke
# l_k = np.prod(?? np.delete(??)??)/ np.prod(?? np.delete(??)??)
# --------------------------------------------
werom l_k
def call(self, x_arr):
""""""
De metoade om it objekt callable te meitsjen (sjoch de koade fan 'e matrixmetoade).
'x_arr' is in set fan opjne punten (in numpy array). Jo moatte brke
self.data_x en self.data_y te finen de ynterpolearre tfier fan de
polynoom foar alle eleminten fan 'x_arr'.
Implementearje sa't jo wolle, mar jo 'totale' numpy array wr't it i'e elemint
p_x_arr[i] stiet foar de ynterpolearre wearde fan p(x_arr[i]).
""""""
# inisjalisearje mei nul
p_x_arr = np.zeros(len(x_arr))
# --------------------------------------------
# JIN KODE HJIR
raise NotImplementedError()
#
# HINT: Soe der tsjen moatte
# foar i, x yn enumerate(x_arr):
# foar k yn berik (self.degree +1):
#??????
# p_x_arr[i]=??? self.data_y[k]??? sels.l(k, x)
# --------------------------------------------
werom p_x_arr"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

14. Identify the magic flight in The Blues Brothers.

Answered: 1 week ago

Question

List the different categories of international employees. page 642

Answered: 1 week ago

Question

Explain the legal environments impact on labor relations. page 590

Answered: 1 week ago