Sep-18-2019, 12:34 AM
Hello
I am preparing for a test in numerical analysis and I am new to python and therefore dont know the syntax and all stuff. If anyone can make this program for me it will help a lot as I could use it as a template on the other numerical analysis problems. I know is sounds weird but the other numerical analysis probles is also the same type of problems. I have this following python code:
I am preparing for a test in numerical analysis and I am new to python and therefore dont know the syntax and all stuff. If anyone can make this program for me it will help a lot as I could use it as a template on the other numerical analysis problems. I know is sounds weird but the other numerical analysis probles is also the same type of problems. I have this following python code:
import auto_test_tools as att ''' Implement a function that can compute the elements of the recurrence relation, that we mathematically define as follows H(n) = 2 H(n-1) + 1 H(1) = 1 The function should take as input, N, the number of elements to compute using the recurrence relation and as output the procedure should return the list H[0], H[1], H[2],..,H[N-1]. Observe that Python indexing is different from the mathematical definition given above. Your code must deal with this. Implement both a recursive and iterative version of the function. ADVICE: Submit your solution even if your code is not running or your score is less than 100% ''' def generate_from_relation_recursively(N: int, n: int = 0, H=[]) -> list: """ Generate a list of elements from a given recurrence relation using a recursive approach. :param N: The number of elements to generate. :param n: The current index of the element that should be generated. :param H: The current elements that have been generated (holds n-1 elements when invoked). :return: The resulting data list after having added the n-element to the list """ return [] # TODO Write your own code here! def generate_from_relation_iteratively(N: int) -> list: """ Generate a list of elements from a given recurrence relation using an iterative approach. :param N: The number of elements to generate. :return: The resulting list """ return [] # TODO Write your own code here! att.start() att.begin_task('Task 1') y = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023] x = generate_from_relation_recursively(10) att.list_is_close(x, y, 10e-7, att.get_linenumber(), ' recursive test failed') att.end_task() att.begin_task('Task 2') z = generate_from_relation_iteratively(10) att.list_is_close(z, y, 10e-7, att.get_linenumber(), ' iterative test failed') att.end_task() att.stop()