> ## Equation Graphing (#176) ... > You can trust the user to input a syntactically correct function, but > don't forget that it might behave badly for certain values of x (e.g. > 1/x where x=0). Style points for making the main loop look trivial :) I went for style points. :) 1/x where x = 0 is handled nicely too. graph.rb: #!/usr/bin/ruby def usage puts "USAGE: #{File.basename($0)} <equation> <xmin> <xmax> <ymin> <ymax>" exit 42 end eq = ARGV.shift || usage usage unless ARGV.length == 4 cmd = "set xr [%f:%f]; set yr [%f:%f]; set tit '%s'; plot %s w li notitle" IO.popen("gnuplot -persist", "w") do |plot| plot.puts cmd % [ARGV.collect { |a| a.to_f }, eq, eq].flatten end -- Posted via http://www.ruby-forum.com/.