Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import numpy as np
  2. import pylab as pl
  3.  
  4. Y, X = np.mgrid[-10:10:100j, -10:10:100j]
  5. # Domain Parameters
  6. a = 3
  7. bb = 7
  8. def f(x):
  9. return x**3 -a*x + bb
  10.  
  11. ###first point P
  12. px = -2.0
  13. py = np.sqrt(f(px))
  14. ###second point Q
  15. qx = -0.5
  16. qy = np.sqrt(f(qx))
  17.  
  18. print "point p x:%s y:%s" % (px,py)
  19. print "point q x:%s y:%s" % (qx,qy)
  20. ### Slope
  21. k = (qy - py)/(qx - px)
  22. b = -px*k + py
  23. print "Slope: %s" % k
  24.  
  25. ##Point Addition
  26. realx = pow(k,2) - qx - px
  27. realy = qy + k * (realx-qx)
  28.  
  29. ## Plotting
  30. pl.contour(X, Y, Y**2 - f(X), levels=[0])
  31. plt.plot(px,py, linestyle='-', marker='o', color='y')
  32. plt.plot(qx,qy, linestyle='-', marker='o', color='r')
  33. plt.plot([realx,realx],[-realy,realy], linestyle='--', marker='o', color='r')
  34.  
  35. pl.plot([px,realx],[py,realy],linestyle="--")
  36. pl.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement