      # Calculate Ratios?

3 replies to this topic

### #1 kevinator9

kevinator9

Casio Freak

• • Members
•    • 125 posts

• Calculators:

Posted 12 November 2007 - 09:27 AM

Is there a way to calculate ratios? Even ones with more then two numbers? EG 24:122:164
Thanks

### #2 Guest_Guest_vanhoa_*_*

Guest_Guest_vanhoa_*_*
• • Guests

Posted 12 November 2007 - 10:48 AM

{24,122,164}/gcd(22,gcd(122,164))

You can use Kilburn's program to write a function like:

function ratios(vallist):

```local i,g
g=vallist
for 2->i to dim(vallist)
g=gcd(vallist[i],g)
next
return vallist/g```

### #3 kevinator9

kevinator9

Casio Freak

• • Members
•    • 125 posts

• Calculators:

Posted 12 November 2007 - 06:13 PM

Thanks Vanhoa. Saved that as an EAct so I can remeber And whats the calculation for 2 numbers and 4 numbers? Thanks

### #4 Guest_Guest_vanhoa_*_*

Guest_Guest_vanhoa_*_*
• • Guests

Posted 13 November 2007 - 05:35 AM

If g is the gcd of n numbers a1,a2,...,an, the ratios of them are a1/g:a2/g:...:an/g

Example with {2,4,6,8}: {2,4,6,8}/gcd(2,gcd(4,gcd(6,8))

Sorry I'm not have my CP here so I can not create the function with PRGM. So here is the code in CPLua

```require("cas","table")

function ratios(...)
local vgcd,i
vgcd=tostring(arg)
for i=2,#arg do
vgcd=tostring(cas.gcd(arg[i],vgcd))
end
end

export{ratios=ratios}```

And then to calculate the ratios of 2,4,6,8 for example you can call print(ratios(2,4,6,8))

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users 