From: Kevin Brown Date: 2005-12-10T06:16:55+09:00 Subject: Re: Equation graphing software? On Friday 09 December 2005 14:58, Steve Litt wrote: > On Friday 09 December 2005 01:22 pm, Eric Lavigne wrote: > > >Does Ruby have any modules useful in graphing equations like y=x**2+5, > > >y**2+x**2=16, 4y+3x=28, and the like? > I already checked out gnuplot and had some problems: > > 1) It doesn't take y**2+x**2=16, but instead requires you to solve for y > and put in (16-x**2)**0.5, which gives you only the upper half of the > circle. > > 2) I thought, OK, I'll make all the points in Ruby, and pipe them to > gnuplot. No joy -- gnuplot's interpolation between points is stupid -- all > but bezier just produce a straight line, and bezier produces cusps where > there aren't any. I spoze I could send LOTS of points, and that might work. > > Which brings up the next point -- algorithm. Remember, I want the full > y**2+x**2=16, not the right side solved for y. > > I'm thinking I start by setting the right side to 0, so it would be > y**2+x**2-16=0. That's OK in this situation. Then I walk up each axis until > I find a point where the right side shifts from positive to negative or > vice versa. Interpolate, try again, interpolate again til I have a > reasonably close point. Now go out maybe 0.1 in each direction and find > points. Now calculate slopes, go out some more along that slope and do it > again. Pretty soon I've traced out all relevant points on a continuous > curve (this won't work with discontinuous curves). > > Now that you see the algorithm I was contemplating, you probably understand > why I was hoping Ruby had a module that produces points for me :-) Use the GNU Graph utility. It has no problem plotting regions and all kinds of cool things. You just give it a list of points in the right order, and that's hunky dory. (so if you got negative and positive, as is the case for your above equation, just give both (but obviously in the right order) and you'll get your circle. http://www.gnu.org/software/plotutils/manual/html_mono/plotutils.html#SEC2 And actually, I'm currently producing a ruby wrapper for this very program that will be LGPL'ed or BSD'ed, so how long can you wait to have this functionality?