Page 1 of 1

import sympy def symbolicFn(n,x,y): # YOUR CODE HERE from nose.tools import assert_equal import sympy x, y = sympy.s

Posted: Wed Apr 27, 2022 3:31 pm
by answerhappygod
Import Sympy Def Symbolicfn N X Y Your Code Here From Nose Tools Import Assert Equal Import Sympy X Y Sympy S 1
Import Sympy Def Symbolicfn N X Y Your Code Here From Nose Tools Import Assert Equal Import Sympy X Y Sympy S 1 (19.21 KiB) Viewed 78 times
Import Sympy Def Symbolicfn N X Y Your Code Here From Nose Tools Import Assert Equal Import Sympy X Y Sympy S 2
Import Sympy Def Symbolicfn N X Y Your Code Here From Nose Tools Import Assert Equal Import Sympy X Y Sympy S 2 (86 KiB) Viewed 78 times
import sympy
def symbolicFn(n,x,y):
# YOUR CODE HERE
from nose.tools import assert_equal
import sympy
x, y = sympy.symbols('x y')
# Check that we get back the constant 1 as a polynomial in x and y
(even though the only power is x^0y^0)
assert_equal(symbolicFn(0,x,y),sympy.Poly(1,x,y,domain=sympy.QQ))
from nose.tools import assert_raises
import sympy
x, y = sympy.symbols('x y')
assert_raises(ValueError,symbolicFn,0,1,1)
from nose.tools import assert_equal
import sympy
x, y = sympy.symbols('x y')
# assert_equal(symbolicFn(1,x,y),sympy.Poly(x/2-y**2,x,y))
assert_equal(symbolicFn(1,x,y),sympy.Poly(-y**2+x/2,x,y,domain=sympy.QQ))
from nose.tools import assert_equal
import sympy
x, y = sympy.symbols('x y')
assert_equal(symbolicFn(3,x,y),sympy.Poly(1/4*x**3*y**2 -
1/2*x**2*y**4 - 3/4*x*y - 5/16*x +
5/8*y**2,x,y,domain=sympy.QQ))
from nose.tools import assert_equal
import sympy
The sequence of functions Fn(x, y) for (n > 0) is defined by the recurrence formula Fo(x, y) = 1, F1(x, y) = *- y2 = and 2n? Fn+1 (x, y) = 2nxyFn(x, y) – (2n + 1)Fn–1(x, y), = n>1.
(b) In addition to working numerically we can also use SymPy to study the functions Fn symbolically and obtain explicit expressions. Use SymPy to write a function symbolicFn which gives an expression for Fn(x, y) as a polynomial in x and y of the form E a[i, j]x'y', where ali, j) are simply some coefficients. An example of such an expression is xy + 2x4y2 + 13 where the coefficients would be a(1, 1) = 1, a(4, 2) = 2, a(0, 3) = 1 and all other ali, j) are zero. = The function should take a non-negative integer n and symbolic values for x and y (as given by e.g. x, y = sympy. symbols ('x y') ) as input and output a polynomial in x and y of the type sympy. Poly with domain the rational numbers (i.e. sympy. QQ ). • If n is not a non-negative integer the function should raise a ValueError • If x or y are not symbolic expressions (i.e. of type sympy.core. symbol. Symbol ) then a ValueError should be raised. Hints: you might find the functions .as_poly() and sympy.Poly useful.