-#!/usr/bin/env python
-# Copyright (C) 2012-2016 CEA/DEN, EDF R&D
+#!/usr/bin/env python3
+# Copyright (C) 2012-2020 CEA/DEN, EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
tmp = scipy.poly1d([0])
result=scipy.poly1d([0])
- for i in points.keys():
+ for i in points:
numerator=scipy.poly1d([1])
denom = 1.0
- for j in points.keys():
+ for j in points:
if (i != j):
tmp = scipy.poly1d([1,-j])
numerator = numerator * tmp
def sortdict(points):
# Sort this dictionary by keys and returns 2 lists, the list of X
# and the list of Y, the whole ordered by X
- keys = points.keys()
- keys.sort()
+ keys = sorted(points.keys())
return keys, [points[key] for key in keys]
import pylab
"""
arrX=numpy.arange(start, stop, step, dtype='float64')
# function is a callable
- arrY=map(function,arrX)
+ arrY=list(map(function,arrX))
pylab.plot(arrX, arrY)
pylab.show()
def TEST_lagrange_01():
input = {0.:5, 0.2:10, 0.9:10, 0.6:21, 1:8}
polynom = lagrange(input)
- print polynom
+ print(polynom)
plot(function=polynom, start=0., stop=1., step=0.001)
def TEST_lagrange_02():
input = {0.:0., 0.5:1., 1.:0.}
polynom = lagrange(input)
- print polynom
+ print(polynom)
plot(function=polynom, start=0., stop=1., step=0.001)
# ---
arrY = [5, 10, 10, 21, 8]
input = points_usingarray(arrX,arrY)
polynom = lagrange(input)
- print polynom
+ print(polynom)
plot(function=polynom, start=0., stop=1., step=0.001)
# Another example using numpy
arrY[3]=2
input = points_usingarray(arrX,arrY)
polynom = lagrange(input)
- print polynom
+ print(polynom)
plot(function=polynom, start=0., stop=1., step=0.001)
# ---
arrY=numpy.cos(10*arrX)
input = points_usingarray(arrX,arrY)
polynom = lagrange(input)
- print polynom
+ print(polynom)
plot(function=polynom, start=0., stop=1., step=0.001)
# General method
arrX=numpy.arange(start=0., stop=1., step=0.1, dtype='float64')
input = points_usingfunction(arrX,chapeau)
polynom = lagrange(input)
- print polynom
+ print(polynom)
plot(function=polynom, start=0., stop=1., step=0.001)