Is there a way to calculate ratios? Even ones with more then two numbers? EG 24:122:164
Thanks
Calculate Ratios?
Started by
kevinator9
, Nov 12 2007 09:27 AM
3 replies to this topic
#1
Posted 12 November 2007 - 09:27 AM
#2 Guest_Guest_vanhoa_*_*
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):
You can use Kilburn's program to write a function like:
function ratios(vallist):
local i,g g=vallist[1] for 2->i to dim(vallist) g=gcd(vallist[i],g) next return vallist/g
#3
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
And whats the calculation for 2 numbers and 4 numbers? Thanks
#4 Guest_Guest_vanhoa_*_*
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
And then to calculate the ratios of 2,4,6,8 for example you can call print(ratios(2,4,6,8))
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[1]) for i=2,#arg do vgcd=tostring(cas.gcd(arg[i],vgcd)) end return tostring(cas("{"..table.concat(arg,",").."}/("..vgcd)) 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))
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users