Question: In Python. 2. Floating point operations need to be done with care. An example of a simple computation when things go awry: The Verhulst equation

 In Python. 2. Floating point operations need to be done with

In Python.

2. Floating point operations need to be done with care. An example of a simple computation when things go awry: The Verhulst equation arises from popula- tion modelling studies Here we examine compute with the Verhulst equation in two ways: (We will explore this equation in later labs). p(n + 1) = p(n) +r.p(n).(1 p(n)) Evaluate the equation in two ways: (i) As written above. (ii) p(n+1) = (1+r).p(n) - r.p(n)2. Use r = 3 and use p(0) = 0.01 as the initial condition. Print the two columns side-by-side with their difference in the third column. Formatted printing. Formatting floats, allows us to specify the number of digits before and after the decimal point: The new version of the for- mat string for floats in Python: Assume p, q are floats declared in your program. The formatted string: print('p is : {0:12.10f}, q is: {1:8.3f}'.format(p, q)) prints argument 0 (p) in 12 digits with 10 digits after the decimal and argument 1 (q) with 8 digits, 3 of them after the decimal. The 'f' tells the interpreter to print the number as a 'float' Print p(n) calculated the two ways specified with 12 digits after the deci- mal. When i.e. at what iteration) do the values start to differ? Run your program for 50 iterations and observe the difference in the two output answers. The point of this exercise is that the interactions of the slight round-off errors in floating points can be magnified by propagation of the error. 2. Floating point operations need to be done with care. An example of a simple computation when things go awry: The Verhulst equation arises from popula- tion modelling studies Here we examine compute with the Verhulst equation in two ways: (We will explore this equation in later labs). p(n + 1) = p(n) +r.p(n).(1 p(n)) Evaluate the equation in two ways: (i) As written above. (ii) p(n+1) = (1+r).p(n) - r.p(n)2. Use r = 3 and use p(0) = 0.01 as the initial condition. Print the two columns side-by-side with their difference in the third column. Formatted printing. Formatting floats, allows us to specify the number of digits before and after the decimal point: The new version of the for- mat string for floats in Python: Assume p, q are floats declared in your program. The formatted string: print('p is : {0:12.10f}, q is: {1:8.3f}'.format(p, q)) prints argument 0 (p) in 12 digits with 10 digits after the decimal and argument 1 (q) with 8 digits, 3 of them after the decimal. The 'f' tells the interpreter to print the number as a 'float' Print p(n) calculated the two ways specified with 12 digits after the deci- mal. When i.e. at what iteration) do the values start to differ? Run your program for 50 iterations and observe the difference in the two output answers. The point of this exercise is that the interactions of the slight round-off errors in floating points can be magnified by propagation of the error

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!