Suppose you want to divide up the interval a b into n 1 sub

Suppose you want to divide up the interval (a, b) into n + 1 sub-intervals of equal length. Using a list comprehension only, but not using either a For or While loop, write a program to determine the end points of each interval. Verify that your program works on the following: (a, b) = (0, 10);n = 10; (a, b) = (3, 17); n = 19; (a, b) = (-4.72, 6.98); n = 12.

Solution

[a,b] = [3,17];
n = 19;
interval = [ a + ((b-a)*i + 0.0)/n for i in range(n+1) ];
print interval;

 Suppose you want to divide up the interval (a, b) into n + 1 sub-intervals of equal length. Using a list comprehension only, but not using either a For or Whil

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site