Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Aufgabe 7
- def graddesc( A, x0, step=0.1 ):
- xi = x0
- # create the result matrix and save the initial value
- results = np.empty([50, 2])
- results[0, 0] = xi[0]
- results[0, 1] = xi[1]
- # complete the matrix with the given formula
- for i in range(1, 50):
- xi = xi + step * (b - np.matmul(A, xi))
- results[i, 0] = xi[0]
- results[i, 1] = xi[1]
- return results
- # generate the values with the same intial value as in the lecture
- values = graddesc(A, np.array([-4, -4]))
- plt.plot(values[:, 0], values[:, 1])
- plot_f( plt.gca() )
- # Aufgabe 8, keine Ahnung ob das richtig ist, sieht aber so aus
- xvalues = np.arange(1, len(history) + 1) # ascending array from 1 to 307
- yvalues = np.empty(len(history))
- for i in range(len(history)):
- yvalues[i] = np.linalg.norm(A@history[i] - f) # add the residual norm in this iteration
- plt.semilogy(xvalues, yvalues)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement