Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Given an integer N, it is required to compute the sum of the cubes of the num

ID: 3762300 • Letter: 1

Question

1. Given an integer N, it is required to compute the sum of the cubes of the numbers from 1 to N. The sum can be computed directly or analytically by the following formula: S = 13 + 23 + 33 + · · · + N 3 = 1 4 N 2 (N + 1)2 (1) a. Let N = 20. Compute the sum by the following 5 methods, using: (1) a for-loop, (2) a conventional while-loop, (3) a forever while-loop, (4) the vectorized sum function, and, (5) the above analytical formula. b. Write a function, say, fsum.m, that employs a switch structure and evaluates the sum by any of the above 5 methods, with method 5 being the default method. It must have the following usage, where m is the method number, m = 1, 2, 3, 4, 5: S = fsum(N,m); c. The sum S grows with increasing N. Using your function fsum and a forever-while loop determine the smallest N such that S > 106 . Repeat using a conventional while-loop.

Explanation / Answer

i=1; sum=0; while (i < 10) cube = i * i * I; sum = sum + cube; i++; end while(true) cube = i * i * I; sum = sum + cube; i++; end for a = 10:20 sum += (a*a*a); end n=15; sum = pow(((n * (n + 1) ) / 2),2); for n = 1:15 V(n) = pow(((n * (n + 1) ) / 2),2); end