You will be given three numbers: base, nstart, and nend. Write a MATLAB script that will compute the sum of a sequence of both the distinct powers of base as well as sums of distinct powers of base. Your sequence should start with the 'nstart'th term and end with the 'nend'th term. For example:
The first several sums of the distinct powers of 4 are:
Since nstart=2 and nend=6 in this example, you take the second through the sixth terms of this sequence. The correct output would be 4+5+16+17+20, or 62. Notice that the number 8 does not occur in this pattern. While 8 is a multiple of 4, 8=4^1+4^1. Because there are two 4^1 terms in the sum, 8 does not qualify as a sum of distinct powers of 4. You can assume that all three will be integers, base>1, and that nstart<nend. Good luck!
I'm having some trouble understanding the problem. Could you provide an example for test 7?
base=7;nstart=1;nend=10;y_correct=1265;
My understanding of the problem leads me to believe the answer should be 1600: 1 + 7 + 8 + 49 + 50 + 56 + 343 + 344 + 350 + 392
You've almost got it, bmtran. You are missing 7^2 + 7^1 + 7^0 = 57 in your example. Put that in, remove the 392 (since that's term #11 in the sequence) and you have the correct answer.
Thanks, that makes sense. I was under the impression that it could only be the sum of 2 distinct powers based on the example.
I've changed the description to make it a bit clearer that you can use any number of terms in the sequence. Hope this helps.
Is there any constraint on using toolboxes ? because the solution i proposed works fine if you have the communication system toolbox installed.
Adel, there are some toolboxes that Cody is able to use, and some that it can't. Since this (otherwise valid) solution doesn't seem to work, it looks like the communication system toolbox is not installed for Cody. Sadly, that's something I can't control while making the problems.
Cf, Problem 337.
It's too bad that Cody doesn't have access to nansum()...
but it now has sum(...,'omitnan')
And it worked just the same. Thanks.
I had to know...
Remove all the words that end with "ain"
1056 Solvers
Find state names that start with the letter N
481 Solvers
439 Solvers
233 Solvers
50 Solvers