Unformatted text preview: What would % it be in terms of f('3',4)? % - If my input was f('312',4), what would my output be? What would % it be in terms of f('31',4)? % (etc.) %Constraints: %In order to receive credit for this problem, you MUST use recursion. %Also, you may not use dec2bin, bin2dec, base2dec, dec2base or any other %function which changes the base of a number for this problem. Problems %using these functions are subject to an automatic zero. if isempty(str) %terminating condition num = 0; %the number will equal 0 when there is an empty string else number = str2num(str(1)); %converts the first element of the string to a number so it can me %operated on mathematically num = chgBase(str(2:end),numin) + number.*numin.^(length(str)-1); %clones the original function from the second position to the end, with %the same base, and adds the number from the first position in the %string multiplied by the base number raised to the length-1 power end end...
View Full Document
- Spring '08
- Recursion, Binary numeral system, Decimal, Elementary arithmetic, Numeral system