Compare commits
2 Commits
509438c7ef
...
3367c775b9
Author | SHA1 | Date |
---|---|---|
schrom01 | 3367c775b9 | |
schrom01 | ea8547fcfc |
Binary file not shown.
|
@ -0,0 +1,37 @@
|
||||||
|
import math
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
|
def f(x):
|
||||||
|
return math.pow(math.e, math.pow(x, 2)) + math.pow(x, -3) - 10
|
||||||
|
|
||||||
|
|
||||||
|
def f_diff(x):
|
||||||
|
return 2 * x * math.pow(math.pow(math.e, x), 2) - 3 * math.pow(x, -4)
|
||||||
|
|
||||||
|
|
||||||
|
def newtonStep(x0, function, function_diff):
|
||||||
|
return x0 - (function(x0)) / (function_diff(x0))
|
||||||
|
|
||||||
|
def simpleNewtonStep(x0, function, function_diff_x0):
|
||||||
|
return x0 - ((function(x0)) / (function_diff_x0))
|
||||||
|
|
||||||
|
def newton(x0, iterations, function, function_diff):
|
||||||
|
print("Newton Verfahren:")
|
||||||
|
x = []
|
||||||
|
x.append(x0)
|
||||||
|
print("x" + str(0) + ":", str(x[0]))
|
||||||
|
for i in range(iterations):
|
||||||
|
x.append(newtonStep(x0=x[i], function=function, function_diff=function_diff))
|
||||||
|
print("x" + str(i + 1) + ":", str(x[i + 1]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
newton(x0=2, iterations=4, function=f, function_diff=f_diff)
|
||||||
|
simpleNewton(x0=0.5, iterations=4, function=f, function_diff=f_diff)
|
Loading…
Reference in New Issue