[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Equation graphing software?

Steve Litt

12/9/2005 12:52:00 PM

Hi all,

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.troublesh...
slitt@troubleshooters.com


11 Answers

lavigne.eric@gmail.com

12/9/2005 6:18:00 PM

0

>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?

gnuplot does this: http://gnu...
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.

G.Durga Prasad

12/9/2005 6:37:00 PM

0

http://rubyforge.org/projec...

Module providing useful methods for interfacing with a Gnuplot
process. The homepage provides the details of its use.
Prasad
On 12/9/05, Steve Litt <slitt@earthlink.net> wrote:
> Hi all,
>
> 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.troublesh...
> slitt@troubleshooters.com
>
>


Gary Watson

12/9/2005 8:24:00 PM

0

Steve Litt wrote:
> Hi all,
>
> 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.troublesh...
> slitt@troubleshooters.com
>
>
I might be misuderstanding what you want, but really all you need to do
is to evaluate the expression by supplying sucessive values for x.

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.

Kevin Brown

12/9/2005 9:17:00 PM

0

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...

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?


Dan Diebolt

12/9/2005 9:23:00 PM

0

>Use the GNU Graph utility.

Octave uses GNU Graphics and it can solve your implicit equations for points.


---------------------------------
Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping

Chad Perrin

12/9/2005 10:05:00 PM

0

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...
>
> 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.ap... ]

unix virus: If you're using a unixlike OS, please forward
this to 20 others and erase your system partition.


Kevin Brown

12/11/2005 5:23:00 AM

0

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/plotutil...
> >2
> >
> > 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?

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.


ljw1001@gmail.com

12/11/2005 3:08:00 PM

0

Generally speaking, I prefer BSD (or Apache) licenses for commercial
work, though for most purposes LGPL is fine. It really depends on
your intentions since you did the heavy lifting.

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.

On 12/11/05, Kevin Brown <blargity@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/plotutil...
> > >2
> > >
> > > 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?
>
> 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.
>
>


Kevin Brown

12/11/2005 3:39:00 PM

0

On Sunday 11 December 2005 09:07, Larry White wrote:
> Generally speaking, I prefer BSD (or Apache) licenses for commercial
> work, though for most purposes LGPL is fine. It really depends on
> your intentions since you did the heavy lifting.
>
> 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 <blargity@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/plot...
> > > >#SEC 2
> > > >
> > > > 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?
> >
> > 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.


Sky Yin

12/11/2005 8:24:00 PM

0

A ruby noob question: If I want to run an external program within ruby code
(instead of running it outside like the example you gave), how can I pass a
string through the pipeline to the program?

Thanks

On 12/9/05, Eric Lavigne <lavigne.eric@gmail.com> 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?
>
> gnuplot does this: http://gnu...
> 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.
>
>
>