Advertisement
Guest User

Untitled

a guest
May 31st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. import numpy as np
  2. import numpy.linalg as la
  3.  
  4. def F1(x):
  5.     x_, y_ = x.item(0), x.item(1)
  6.     return np.matrix([[np.sin(x_+.937)-.389*y_-1.822],
  7.                       [x_+np.cos(y_-.149)-.59]])
  8.  
  9. def F2(x):
  10.     x_, y_ = x.item(0), x.item(1)
  11.     return np.matrix([[np.tan(x_*y_+.937) - np.power(x_, 2)],
  12.                       [.803*np.power(x_, 2)-.389*np.power(y_, 2)-1]])
  13.  
  14. def W1(x):
  15.     x_, y_ = x.item(0), x.item(1)
  16.     return np.matrix([[np.cos(x_+.937), -.389],
  17.                       [1, -np.sin(y_-.149)]])
  18.  
  19. def W2(x):
  20.     x_, y_ = x.item(0), x.item(1)
  21.     a00 = y_/(np.cos(x_*y_+.937)**2) - 2*x_
  22.     a01 = x_/(np.cos(x_*y_+.937)**2)
  23.     a10 = 1.606*x_
  24.     a11 = -0.778*y_
  25.     a = np.matrix([[a00, a01],
  26.                    [a10, a11]])
  27.     return a
  28.  
  29. x = np.matrix([[1], [-3]])
  30. _x = np.matrix([[1], [1]])
  31. lambd = -la.inv(W1(x))
  32. k = 0
  33. while (la.norm(F1(x)) > 10e-5) or   (la.norm(_x - x) > 10e-5):
  34.     k += 1
  35.     _x = x
  36.     x = x + np.dot(lambd, F1(x))
  37.     print('step#{}\nx={}\nF={}\n|F|={}'.format(
  38.         k, x, F1(x), la.norm(F1(x))))
  39. print(x)
  40.  
  41. x = np.matrix([[-1], [0]])
  42. _x = np.matrix([[1], [1]])
  43. k=0
  44. while (la.norm(F2(x)) > 10e-5) or   (la.norm(_x - x) > 10e-5):
  45.     k+=1
  46.     _x = x
  47.     delta = la.solve(W2(x), -F2(x))
  48.     x = x + delta
  49.     print('step#{}\nx={}\nF={}\n|F|={}'.format(
  50.         k, x, F2(x), la.norm(F2(x))))
  51. print(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement