finished newton polynom
This commit is contained in:
parent
7310527c78
commit
201931050a
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.11" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Python-Math-Algorithms.iml" filepath="$PROJECT_DIR$/.idea/Python-Math-Algorithms.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -14,27 +14,32 @@
|
||||||
# Licensed under the GPLv2 License, Version 2.0 (the "License");
|
# Licensed under the GPLv2 License, Version 2.0 (the "License");
|
||||||
# Copyright (c) Sven Vogel
|
# Copyright (c) Sven Vogel
|
||||||
|
|
||||||
def combine(p0, p1):
|
def combine_n(points):
|
||||||
return (p1[1] - p1[0]) / (p0[1] - p0[0])
|
k = len(points)
|
||||||
|
|
||||||
|
|
||||||
def combine_n(*points):
|
|
||||||
k = len(points) - 1
|
|
||||||
|
|
||||||
if k == 1:
|
if k == 1:
|
||||||
return combine(points[0], points[1])
|
return points[0][1]
|
||||||
|
elif k == 2:
|
||||||
|
return (points[1][1] - points[0][1]) / (points[1][0] - points[0][0])
|
||||||
else:
|
else:
|
||||||
return (combine_n(points[1:k]) - combine_n(points[0:(k - 1)])) / (points[k][0] - points[0][0])
|
return (combine_n(points[1:k]) - combine_n(points[0:(k - 1)])) / (points[k - 1][0] - points[0][0])
|
||||||
|
|
||||||
|
|
||||||
def newton_polynom(*points):
|
# returns a polynom that will intersect all supplied points as long as
|
||||||
for x in range(len(points)):
|
# the number of points is bigger than 1
|
||||||
|
def newton_polynom(points):
|
||||||
|
for x in range(1, len(points)):
|
||||||
|
|
||||||
print(combine_n(points[0:x]))
|
if x == 1:
|
||||||
|
print(points[0][1], end=' + ')
|
||||||
|
else:
|
||||||
|
print(end=' + ')
|
||||||
|
|
||||||
|
print(combine_n(points[0:(x + 1)]), end='')
|
||||||
|
|
||||||
for y in range(x):
|
for y in range(x):
|
||||||
print(format(" * (x - %s)", points[y][0]))
|
print(" * (x - {value:.2f})".format(value=points[y][0]), end='')
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
newton_polynom([1, 2], [3, 4], [9, -5])
|
newton_polynom([[-1, 5], [2, -1], [3, -1], [4, 5], [8, 9]])
|
||||||
|
|
Loading…
Reference in New Issue