Answered step by step
Verified Expert Solution
Question
1 Approved Answer
f(x) = 2*x count = srange(0,10) vals = [3] for i in count: a = vals[i] b = f(a) vals.append(b) list_plot(vals) Make the above script
f(x) = 2*x
count = srange(0,10)
vals = [3]
for i in count:
a = vals[i]
b = f(a)
vals.append(b)
list_plot(vals)
- Make the above script a function called iterate. This function should take no inputs (yes, this is OK) and return the list of values. Test your function. HINT: The header of a function that takes no inputs should have the form def my_function_name():
- Copy and modify your iterate function so that the number of times the iteration should be performed is an input. (Use a descriptive name.) Test your function with several different input values. HINT: Where does this number appear in the example?
- Copy and modify the previous version of your iterate function so that the initial value is also an input. As before, test your function with several different input values.
- Copy and modify the previous version of your iterate function so that the function to be iterated is also an input. Test iterate with at least two different functions. HINT: What line of code will you need to remove when modifying the previous version of the function?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started