Page 1 of 1

# Test that 'evalFn' returns a float if a scalar is input. from nose.tools import assert_equal assert_equal(type(evalFn(

Posted: Wed Apr 27, 2022 3:31 pm
by answerhappygod
Test That Evalfn Returns A Float If A Scalar Is Input From Nose Tools Import Assert Equal Assert Equal Type Evalfn 1
Test That Evalfn Returns A Float If A Scalar Is Input From Nose Tools Import Assert Equal Assert Equal Type Evalfn 1 (19.21 KiB) Viewed 36 times
Test That Evalfn Returns A Float If A Scalar Is Input From Nose Tools Import Assert Equal Assert Equal Type Evalfn 2
Test That Evalfn Returns A Float If A Scalar Is Input From Nose Tools Import Assert Equal Assert Equal Type Evalfn 2 (37.2 KiB) Viewed 36 times
# Test that 'evalFn' returns a float if a scalar is input.
from nose.tools import assert_equal
assert_equal(type(evalFn(1,1,1)),float)
# Test that 'evalFn' outputs the correct values for some values
of n
from nose.tools import assert_equal,assert_almost_equal
assert_almost_equal(evalFn(4,1,1),0.548611111111111,delta=1e-10)
# Hidden tests that 'evalFn' outputs the correct values for some
other values of n
from nose.tools import assert_equal,assert_almost_equal
assert_equal(evalFn(1,3,100),-9998.5)
# Hidden tests that 'evalFn' outputs the correct values for some
other values of n
from nose.tools import assert_equal,assert_almost_equal
# Test that the 'evalFn' returns a numpy array of correct shape
if the inputs are numpy arrays.
from nose.tools import
assert_equal,assert_almost_equal,assert_raises,assert_true
import numpy as np
x = np.linspace(0,1,2)
y = np.linspace(0,1,3)
X,Y = np.meshgrid(x,y)
assert_equal(type(evalFn(0,X,Y)),np.ndarray)
from nose.tools import
assert_equal,assert_almost_equal,assert_raises,assert_true
import numpy as np
# Test that the 'evalFn' returns a numpy array of correct shape
if the inputs are numpy arrays.
from nose.tools import
assert_equal,assert_almost_equal,assert_raises,assert_true
import numpy as np
x = np.linspace(0,1,2)
y = np.linspace(0,1,3)
X,Y = np.meshgrid(x,y)
assert_equal(evalFn(1,X,Y).shape,(3,2),"Function should return a 3
x 2 grid!")
import numpy as np
x = np.linspace(0,1,2)
y = np.linspace(0,1,3)
X,Y = np.meshgrid(x,y)
assert_true( (evalFn(0,X,Y)==np.ones((3,2))).all())
import numpy as np
x = np.linspace(0,1,2)
y = np.linspace(0,1,3)
X,Y = np.meshgrid(x,y)
assert_almost_equal(evalFn(3,X,Y)[2,1],-0.6875,delta=1e-6)
# Test that 'evalFn' returns the correct values for some input
vectors.
import numpy as np
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.
(a) [5 marks] Write a recursive function (i.e. a function that calls itself) evalFn which evaluates the function Fn with the arguments x and y. . • The function should return a float if the input is a scalar; If the input x and y are both two-dimensional NumPy arrays then the output should also be a two-dimensional NumPy array; • If the input are numpy arrays of different shapes it should raise a ValueError. Hint: You might find it useful to replace n +1 by m and solve for Fm-