Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################
- # Problem 1
- ################
- import sympy as sp
- from sympy import symbols
- x, y, r = symbols('x y r')
- # Solution with just unknown variables swapped
- sol = [{r: sp.sqrt(x ** 2 + y ** 2), y: 2 * x + 0.5}] * 2
- ################
- # Problem 2
- ################
- from sympy.abc import y, x
- from sympy import plot_implicit, Eq
- pl1 = plot_implicit(Eq(x ** 2 + y ** 2, 4), (x, -3, 3), (y, -3, 3), aspect_ratio=(2, 2),
- title="Plotting Ellipsis",xlabel='X axis', ylabel='Y axis', line_color='#323353', show=False,
- markers=[{'args': [-1 / 4, 0], 'color': 'green', 'marker': 'o'},
- {'args': [-3 / 20, 1 / 5], 'color': 'green', 'marker': 'o'}],
- annotations=[
- {'xy': (1, 2.1), 'text': "2y = 4x + 1", 'ha': 'left', 'va': 'bottom', 'color': '#0b5e65'}])
- pl2 = plot_implicit(Eq(2 * y - 4 * x - 1, 0), line_color='#0b5e65', show=False)
- pl1.append(pl2[0])
- backend = pl1.backend(pl1)
- backend.process_series()
- backend.fig.savefig('Problem2.pdf', dpi=150)
- pl1.show()
- ################
- # Problem 3
- ################
- import sympy as sp
- from sympy.abc import x
- def canonical_representation(fractional, irrational=sp.sqrt(2)):
- sqrt_2_exp = fractional(irrational).simplify()
- return sqrt_2_exp.subs(irrational, 0), sqrt_2_exp.coeff(irrational)
- ################
- # Problem 4
- ################
- import sympy as sp
- from sympy.abc import x, a, b, c, d
- def canonical_representation(fractional, irrational=sp.sqrt(2)):
- decomposition = fractional.apart()(irrational)
- sqrt_2_coefficient = decomposition.coeff(irrational)
- return decomposition - irrational * sqrt_2_coefficient, sqrt_2_coefficient
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement