Good gosh, this problem is SO much more complicated than it sounds.
The description is quite unclear, honestly. No hate but there are some things other people need to know before getting started.
1) The coefficient array that is returned needs to be EXACTLY n+1 in length
2) The first coefficient cannot be zero
3) The 'only' constraint doesn't just apply to c_n & c_0, although the assert does check for that. Your coefficient array must be a pyramid (as I now see in the tags). Had to learn that one the hard way.
i.e. c_n = c_0
BUT ALSO ...
c_n+1 = c_1
c_n+2 = c_2
If you're trying to test your code in your own MATLAB console before posting it and the asserts throw errors (as they did with me) use this instead:
assert(isequal(dot(coeff, 4.^flip(0:n)), 10^n))
assert(coeff(1) > 0)
Overall, interesting problem. Slaved away at it because it got me so frustrated but knowing these things would have saved me quite a bit of time. Good luck to future participants.
Hum, actually Highphi is not quite right. This problem is only confusing because we may think that it is requesting to convert a number to base-4, and that's not the case. Coefficients can be any real numbers with the only constraint being that c_n == c_0. For instance, I've found as a valid solution for n=3 (1000): [2.0000, 16.5000, 151.5000, 2.0000]. And there is probably an infinite number of other solutions, we just have to add enough constraints to find one.
One of the few solutions at Cody that actually deserves its place. Tip of the hat to you, sir.
Arrange Vector in descending order
Back to basics 22 - Rotate a matrix
Reverse the elements of an array
Check that number is whole number
Sum of series V
Let's Make A Deal: Criminal Minds
Nodal Voltage of Resistor Ladder Network
The Generalized-N Eggs Problem
Let's Make A Deal: The Player's Dilemma
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office