#resuleve y grafica ecuaciones de primer, segundo y tercer grado @protos.nu@gmail.com require 'rubygems' require 'gruff' require 'launchy' puts "..................." puts ".Grafic Editor v0 ." puts ".By pRotos ." puts "...................\n\n" puts"1)Equacion de primer grado" puts "2)Equacion de segundo grado\n" puts "3)Equacion de tercer grado\n" puts"Elige opcion (pulsa 1, 2 o 3 y enter)" op=gets.chomp puts "Elige el rango:" print "Inferior:" inf=gets.chomp inf=inf.to_i puts "Superior:" sup=gets.chomp sup=sup.to_i case op when "1" puts "y=ax+b\n" print "a=" a=gets.chomp print "b=" b=gets.chomp a=a.to_f b=b.to_f res=-(b/a) puts "Resultado:" puts res ord=[] i=inf o=0 while i < sup y=(a*i)+b ord[o]=y i+=1 o+=1 end g=Gruff::Line.new g.title = "Graficador de equaciones" f= "y= ", a.to_i,"x + ", b.to_i, "" g.data("#{f}", [ord[0], ord[1], ord[2], ord[3], ord[4], ord[5], ord[6], ord[7], ord[8], ord[9], ord[10], ord[11]]) g.labels = {0 => '-5', 1 => '-4', 2 => '-3', 3 => '-2', 4 => '-1', 5 => '0', 6 => '1', 7 => '2', 8 => '3', 9 => '4', 10 => '5'} g.write('funcion.png') print "Grafico guardado en '", Dir.pwd, "' !\n" when "2" puts "y=ax2+bx+c\n" print "a=" a=gets.chomp print "b=" b=gets.chomp print "c=" c=gets.chomp a=a.to_f b=b.to_f c=c.to_f res1=((-b)-(Math.sqrt((b**2)-(4*a*c))))/(2*a) res2=((-b)+(Math.sqrt((b**2)-(4*a*c))))/(2*a) puts "Resultados:" print"x1=", res1, "\n" print"x2=", res2, "\n" ord=[] i="-5" i=i.to_i o=0 while i < 6 y=(a*(i**2))+(b*i)+c ord[o]=y i+=1 o+=1 end g=Gruff::Line.new g.title = "Graficador de equaciones" f="y= ", a.to_i,"x2 + ", b.to_i, "x + ", c.to_i, "" g.data("#{f}", [ord[0], ord[1], ord[2], ord[3], ord[4], ord[5], ord[6], ord[7], ord[8], ord[9], ord[10], ord[11]]) # g.labels = {0 => '-5', 1 => '-4', 2 => '-3', 3 => '-2', 4 => '-1', 5 => '0', 6 => '1', 7 => '2', 8 => '3', 9 => '4', 10 => '5'} g.labels= lab+ci g.write('funcion.png') print "Grafico guardado en '", Dir.pwd, "' !\n" when "3" puts "y=ax3 + bx2 + cx + d\n" print "a=" a=gets.chomp print "b=" b=gets.chomp print "c=" c=gets.chomp print "d=" d=gets.chomp a=a.to_f b=b.to_f c=c.to_f d=d.to_f ord=[] i="-5" i=i.to_i o=0 while i < 6 y=(a*(i*i*i))+(b*(i**2))+(c*i)+d ord[o]=y i+=1 o+=1 end g=Gruff::Line.new g.title = "Graficador de equaciones" f= "y= ", a.to_i, "x3 + ", b.to_i, "x2 + ", c.to_i, "x + ", d.to_i, "" g.data("#{f}", [ord[0], ord[1], ord[2], ord[3], ord[4], ord[5], ord[6], ord[7], ord[8], ord[9], ord[10], ord[11]]) # g.labels = {0 => '-5', 1 => '-4', 2 => '-3', 3 => '-2', 4 => '-1', 5 => '0', 6 => '1', 7 => '2', 8 => '3', 9 => '4', 10 => '5'} g.labels= lab+ci g.write('funcion.png') print "Grafico guardado en '", Dir.pwd, "' !\n" end