Advertisement
mhxion

assignment-13

Feb 6th, 2023 (edited)
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. ################
  2. # Problem 1
  3. ################
  4.  
  5. import sympy as sp
  6. from sympy import symbols
  7.  
  8. x, y, r = symbols('x y r')
  9. # Solution with just unknown variables swapped
  10. sol = [{r: sp.sqrt(x ** 2 + y ** 2), y: 2 * x + 0.5}] * 2
  11.  
  12.  
  13. ################
  14. # Problem 2
  15. ################
  16.  
  17.  
  18. from sympy.abc import y, x
  19. from sympy import plot_implicit, Eq
  20.  
  21. pl1 = plot_implicit(Eq(x ** 2 + y ** 2, 4), (x, -3, 3), (y, -3, 3), aspect_ratio=(2, 2),
  22.                     title="Plotting Ellipsis",xlabel='X axis', ylabel='Y axis', line_color='#323353', show=False,
  23.                     markers=[{'args': [-1 / 4, 0], 'color': 'green', 'marker': 'o'},
  24.                              {'args': [-3 / 20, 1 / 5], 'color': 'green', 'marker': 'o'}],
  25.                     annotations=[
  26.                         {'xy': (1, 2.1), 'text': "2y = 4x + 1", 'ha': 'left', 'va': 'bottom', 'color': '#0b5e65'}])
  27. pl2 = plot_implicit(Eq(2 * y - 4 * x - 1, 0), line_color='#0b5e65', show=False)
  28. pl1.append(pl2[0])
  29. backend = pl1.backend(pl1)
  30. backend.process_series()
  31. backend.fig.savefig('Problem2.pdf', dpi=150)
  32. pl1.show()
  33.  
  34. ################
  35. # Problem 3
  36. ################
  37.  
  38. import sympy as sp
  39. from sympy.abc import x
  40.  
  41. def canonical_representation(fractional, irrational=sp.sqrt(2)):
  42.     sqrt_2_exp = fractional(irrational).simplify()
  43.     return sqrt_2_exp.subs(irrational, 0), sqrt_2_exp.coeff(irrational)
  44.  
  45. ################
  46. # Problem 4
  47. ################
  48.  
  49. import sympy as sp
  50. from sympy.abc import x, a, b, c, d
  51.  
  52.  
  53. def canonical_representation(fractional, irrational=sp.sqrt(2)):
  54.     decomposition = fractional.apart()(irrational)
  55.     sqrt_2_coefficient = decomposition.coeff(irrational)
  56.     return decomposition - irrational * sqrt_2_coefficient, sqrt_2_coefficient
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement