Ask Your Question

Hell_Boy's profile - activity

2021-03-17 21:32:06 +0200 received badge  Popular Question (source)
2018-10-12 22:37:17 +0200 received badge  Student (source)
2018-10-12 18:09:57 +0200 commented question Polynomial interpolation given a mathematic function f(x), an interval [a,b] and a natural number n

Thanks you saved my life.

2018-10-12 14:39:38 +0200 asked a question Polynomial interpolation given a mathematic function f(x), an interval [a,b] and a natural number n

Hi, i'm a computer science bachelor 's student and i'm having some trouble with this exercice, i'd like to get some help since it's my first course using sagemath, thanks, the exercice:

Write a function that takes as input a mathematical function f, an interval [a, b] and a natural n and return the interpolative polynomial of the function in the n + 1 points resulting from dividing the interval into subinterval n of equal length. That is to say, a polynomial p (x) of degree ≤ n such p (xi) = f (xi), where xi = a + i * ((b-a)/n) for all i = 0, ... n. I'm stuck in the way of transforming a list into a matrix. This is what i've tried so far:

def list1(a,b,n):
    return [a+i*r for i in range(n+1)]
def list2(a,b,n):
    for i in range(n+1):
    return l

def functionlist(f,llista):
    return[f(i) for i in llista]

px=matrix(7, 1,list2(1, 5, 6))
py=matrix(7, 1, functionlist(sin, list1(1, 5, 6)))

points= zip(px,py); points

A=matrix(RDF,[[1,px[0],px[0]^2,px[0]^3],[1,px[1],px[1]^2,px[1]^3],[1,px[2],px[2]^2,px[2]^3],[1,px[3],px[3]^2,px[3]^3]]); A

And gives me this error:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-112-a1670df9c827> in <module>()
     19 points= zip(px,py); points
---> 21 A=matrix(RDF,[[Integer(1),px[Integer(0)],px[Integer(0)]**Integer(2),px[Integer(0)]**Integer(3)],[Integer(1),px[Integer(1)],px[Integer(1)]**Integer(2),px[Integer(1)]**Integer(3)],[Integer(1),px[Integer(2)],px[Integer(2)]**Integer(2),px[Integer(2)]**Integer(3)],[Integer(1),px[Integer(3)],px[Integer(3)]**Integer(2),px[Integer(3)]**Integer(3)]]); A

/opt/sagemath-8.3/local/lib/python2.7/site-packages/sage/modules/free_module_element.pyx in sage.modules.free_module_element.FreeModuleElement.__pow__ (build/cythonized/sage/modules/free_module_element.c:15842)()
   2019             NotImplementedError
   2020         """
-> 2021         raise NotImplementedError
   2023     def _repr_(self):


Pls help, thanks.