d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Numerical Computations Help
Prev12
Add Reply New Topic New Poll
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 13 2015 05:15pm
just assume it's an integer then.

start with an example in pure math. show every step.
then write down what logic /conditions you used between each step.
then use variables instead of numerical values.
then convert to pseudocode.
then convert pseudocode to matlab
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 17 2015 07:07pm
Quote (carteblanche @ Sep 13 2015 07:15pm)

start with an example in pure math. show every step.
then write down what logic /conditions you used between each step.
then use variables instead of numerical values.
then convert to pseudocode.
then convert pseudocode to matlab


Did you do these steps yet?
Member
Posts: 7,324
Joined: Dec 22 2002
Gold: 1,261.00
Sep 18 2015 03:01pm
Quote (carteblanche @ Sep 13 2015 03:19pm)
i assume "positive number" means a 32 bit integer?

start with pseudo code to get your logic down, then convert the syntax to matlab.


Why the assumption? There's nothing special about the fractions, just keep iterating over the remainder until you either get an exact result or get to some maximum string length that you decide upon.

rough pseudo code:

result = "1232" //whatever whole part in string format
remainder = 0.123 //whatever the decimal fraction was
maxSteps = 20 //max fraction length in base 12 to approximate the fraction in base 10

for (int step = 0; step < maxSteps AND remainder != 0; step++) {
nextDigit = remainder * 12
result += nextDigit.toInteger().toString()
remainder = nextDigit - nextDigit.toInteger()
}


This post was edited by russian on Sep 18 2015 03:15pm
Go Back To Homework Help Topic List
Prev12
Add Reply New Topic New Poll