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 suppose the two tasks involved are
getting the points, and then graphing them. I'm on kind of a tight schedule
so I hoped not to write either of those from scratch.
Thanks
SteveT
Steve Litt
http://www.troubleshooters.com
sl...@troubleshooters.com
gnuplot does this: http://gnuplot.info/
Gnuplot can create your graphs as files or display them on the screen.
Gnuplot is ordinarily used as a standalone program which reads a
script, but you can make it work with your program by putting gnuplot
at the end of a pipeline. Your program writes gnuplot commands to
standard-out:
ruby myprog.rb | gnuplot
If you need to do something more complicated (or if your OS doesn't
support pipes), creating an object that acts as an output stream to a
gnuplot process would be fairly easy.
Module providing useful methods for interfacing with a Gnuplot
process. The homepage provides the details of its use.
Prasad
for instance to print out the plot points for x**2 which should be a
porabola you could do something like the following
for x in -10..10
puts "x = #{x}: y = #{x**2}"
end
where you simply adjust the step value and range of the for loop to get
the granularity you want.
Ruby makes it even nicer becuase you could take in user input as a
string and then use the eval function to evalute it as in
string = gets
for x in -10..10
puts "x = #{x}: y = #{eval string}"
end
As far as plotting the values in a graphical way, you're going to have
to use one of the GUI toolkits which are available for ruby. TK is a
very fine one which is easy to learn how to use and has the benefit of
coming with ruby by default. I blieve you can plot points and draw on a
TKCanvas widget but you'll have to read the tk docs to figure that out.
---------------------------------
Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping
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?
Are you trying to decide between the two licenses, or are you releasing
it under both?
--
Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ]
unix virus: If you're using a unixlike OS, please forward
this to 20 others and erase your system partition.
I'm going to release it under a commercially friendly license. Let me know if
you have a preference and I'd be happy to be accomodating.
The fewer restrictions, the more commercial entities will like it -
the less I have to explain to the company lawyers the better - but you
need to decide whether you'd be happy in the (fairly unlikely) event
that someone goes off and tries to commercialize a version and keep
their changes proprietary.
Well, I am a commercial entity, and this will be created for my company, so
you're guarenteed to have a permissive license. :-) No worries.
> On 12/11/05, Kevin Brown <blar...@gmail.com> wrote:
> > On Friday 09 December 2005 16:04, Chad Perrin wrote:
> > > On Sat, Dec 10, 2005 at 06:16:55AM +0900, Kevin Brown wrote:
> > > > 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
> > > >#SEC 2
Thanks