From: "baptiste AuguiƩ" Date: 2007-07-01T19:43:01+09:00 Subject: simple math operations on arrays --Apple-Mail-1-968431922 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Hi, Again a very basic problem, I need to create arrays with numerical values, and do *very simple* math operations on each elements. I've tried to install ruby-gsl as suggested but I don't have admin rights on the machine. Here is my try: > radius=0.045 > aspectRatio=[] > longAxis=[] > shortAxis=[] > > 0.5.step(1, 0.1) { |x| aspectRatio << x.to_s } > > longAxis=aspectRatio.collect{ |x| radius.to_f*((x.to_f)**(-2/3)) } > aspectRatio.each_index { |x| shortAxis << longAxis > [x].to_f*aspectRatio[x].to_f} > puts longAxis > puts shortAxis the result is wrong, and it all seems over-sophisticated to me. I must have missed a basic technique. I need three arrays: 'aspectRatio' is just [0.5, 0.6, 0.7, 0.8, 0.9, 1.0], but I want to construct it as a range (call me lazy). The second is constructed doing the same calculation on every element of 'aspectRatio'. The third one needs to access elements of the same index from the previous two arrays, and multiply them together to form the new array. Here is the result I'd expect: > longAxis = > > 0.071433 > 0.063257 > 0.057080 > 0.052218 > 0.048274 > 0.045000 > > shortAxis = > > 0.035717 > 0.037954 > 0.039956 > 0.041774 > 0.043447 > 0.045000 and the result I get: > 0.09 > 0.075 > 0.0642857142857143 > 0.05625 > 0.05 > 0.045 > > 0.045 > 0.045 > 0.045 > 0.045 > 0.045 > 0.045 Any help / advice appreciated, Best regards baptiste --Apple-Mail-1-968431922--