Question

Python 3 programming: Implementing numpy, create a code for the Broyden 1 method of solving roots.

Python 3 programming:
Implementing numpy, create a code for the Broyden 1 method of solving roots.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

from __future__ import division
import numpy as np
import scipy.linalg as sla

def broyden_good(x, y, f_equations, J_equations, tol=10e-10, maxIters=50):
steps_taken = 0
f = f_equations(x,y)
J = J_equations(x,y)
  
while np.linalg.norm(f,2) > tol and steps_taken < maxIters:
s = sla.solve(J,-1*f)
x = x + s[0]
y = y + s[1]
newf = f_equations(x,y)
z = newf - f
  
J = J + (np.outer ((z - np.dot(J,s)),s)) / (np.dot(s,s))
  
f = newf
steps_taken += 1
  
return steps_taken, x, y

tol = 10.0** -15
maxIters = 50
x0 = 1
y0 = 2

def fs(x,y):
return np.array([x + 2*y - 2, x**2 + 4*y**2 - 4])

def Js(x,y):
return np.array([[1,2],[2, 16]])

n, x, y = broyden_good(x0, y0, fs, Js, tol, maxIters=50 )
print("iterations: ", n)
print("x and y: ", x, y)

Output:

Add a comment
Know the answer?
Add Answer to:
Python 3 programming: Implementing numpy, create a code for the Broyden 1 method of solving roots.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT