Reference no: EM132171725
Using Octave
Define: [m, d] = your birthday in the month [m] and on the day [d]
If m + d < 10, set n = m + d + 10. Otherwise, set n = m + d.
Program a FOR loop for the index i varying from 2 to n to create a sum called s1 that adds up all the terms in the form of 1/i^d. After the loop, write ‘s1' on a line by itself to print out the final value of s1.
Next, we ‘vectorize' the problem. Create a vector that is a set of numbers represented by a variable j varying from 2 to n increasing by an increment of one.
When you create this vector, the increment of one must be specified in that line of code. Use the ‘sum' command in Octave to create a sum called s2 that adds up all the terms in the form of 1/j^d.
You will need to use periods to tell Octave to take each value of j in the vector one at a time to form the corresponding term 1/j^d. Afterwards the ‘sum' command will add up all of the resulting terms. At the end, write ‘s2' on a line by itself to print out the final value of s2.
In the end, s2 should equal s1.