From: Matthew Moss Date: 2008-09-05T23:01:34+09:00 Subject: [QUIZ] Equation Graphing (#176) -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The three rules of Ruby Quiz 2: 1. Please do not post any solutions or spoiler discussion for this quiz until 48 hours have passed from the time on this message. 2. Support Ruby Quiz 2 by submitting ideas as often as you can! (A permanent, new website is in the works for Ruby Quiz 2. Until then, please visit the temporary website at . 3. Enjoy! Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone on Ruby Talk follow the discussion. Please reply to the original quiz message, if you can. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- This week's quiz idea provided and written by Martin DeMello. ## Equation Graphing (#176) Back when the world was shiny and new, and BBC Basic my language of choice and necessity, one of the fun little programs I wrote was a simple equation grapher. Two things that made it simple were (i) the ever-useful EVAL function, and (ii) the almost trivial ability to pick a colour and a pair of coordinates and put a friendly glowing pixel onto the screen. Instant gratification writ large. Well, anything that Basic can do, Ruby should be able to, so your task this week is to whip out your favourite graphics toolkit or library and write a program that 1. Asks for a function of one variable, x 2. Asks for the region of the graph to display (xmin, xmax, ymin, ymax) 3. Plots the graph 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 :) Here's a neat little online grapher you can use to visually check your output: . -- Matthew Moss