Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
def solve( *eqs )
ary = []
eqs.each { |x|
# Remove spaces.
x.gsub!( /\s+/, "")
# If variable lacks coefficient, use 1.
x.gsub!( /(\d*\.?\d*)[xy]/ ) {|m| m="1"+m if ""==$1; m}
ary << x.split( /[xy=]+/ )
}
# Remove +'s and convert strings to floats.
ary.map!{|row| row.map!{|s| s.sub(/\+/,"")
s.to_f }}
p ary
mul = ary[0][1] / ary[1][1] * -1
ary[1].map!{ |f| f*mul }
x = (ary[0][2]+ary[1][2])/(ary[0][0]+ary[1][0])
y = (ary[0][2]-ary[0][0]*x)/ary[0][1]
[x, y]
end
x,y = solve( "2x -3y = -8", "x + y =6" )
printf "%g,%g\n", x, y
x,y = solve( "4x - 2y = -28", "-0.5x + y = 5" )
printf "%g,%g\n", x, y