ich bringe mir gerade Python bei und wollte auf diesem Weg hier eine Frage zum Newtonverfahren stellen, genauer: Wenn ich zwei Funktionen definiert habe, wir kann ich einen Startwert in der For-Schleife waehlen?
Dazu poste ich euch nochmal meinen code:
- import numpy as np
- import matplotlib.patches as mpatches
- import matplotlib.pyplot as plt
- def f(x):
- return 2*x + 4*x**2 - 3*x**3 - 1
- def df(x):
- return 2 + 8*x - 9*x**2
- x1 = np.arange(-10,10,0.1)
- n=50
- x[1]=2
- for i in range(1,n):
- x[i+1]=x[i] + f(x)/df(x)
- if df(x) < 0.001:
- break
- plt.figure()
- plt.plot(x1,f(x1),'-b')
- plt.plot(x1,df(x1),'-r')
- black_patch = mpatches.Patch(color='black', label='f(x)')
- plt.legend(handles=[black_patch])
- red_patch = mpatches.Patch(color='red', label='df(x)')
- plt.legend(handles=[red_patch])
- plt.show()
schon jetzt herzlichen Dank fuer euere Ideen!!