From: Todd Benson Date: 2008-02-28T14:02:31+09:00 Subject: Re: Math problem On Wed, Feb 27, 2008 at 9:25 PM, Rimantas Liubertas wrote: > <...> > > > And then I much prefer the algebraic solution I worked out in a few > > seconds on paper when the question was first posed. > <...> > > Father: x > Daugher: y > 4y - x = 0 > (x + 6) / (y+6) = 3 -> 3y + 18 = x + 6 -> 3y - x = -12 > > Coefficients: > 4, -1 > 3, -1 > Constants > 0 > -12 > > >> require 'matrix' > => true > >> require 'rational' > => true > >> k = Matrix[*[[4, -1], [-3, 1]].map{|r| r.map{|x| Rational(x)}}].inverse > => Matrix[[Rational(1, 1), Rational(1, 1)], [Rational(3, 1), Rational(4, 1)]] > >> c = Matrix[[Rational(0)],[Rational(12)]] > => Matrix[[Rational(0, 1)], [Rational(12, 1)]] > >> (k * c).to_a.flatten.map{|e| e.to_i} > => [12, 48] Opposites attract... But that's not rational, is it? Joking aside, I'm actually working on solving nonlinear systems of equations (you know, upside down pendulum, etc.) with Ruby as an exercise; and process time doesn't matter all that much. Todd