Forum: Ruby Equation graphing software?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
slitt (Guest)
on 2005-12-09 14:53
(Received via mailing list)
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 L.
http://www.troubleshooters.com
removed_email_address@domain.invalid
lavigne.eric (Guest)
on 2005-12-09 20:26
(Received via mailing list)
>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://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.
gdprasad (Guest)
on 2005-12-09 20:39
(Received via mailing list)
http://rubyforge.org/projects/rgplot/

Module providing useful methods for interfacing with a Gnuplot
process. The homepage provides the details of its use.
Prasad
pfharlock (Guest)
on 2005-12-09 22:28
(Received via mailing list)
Steve L. wrote:
>
> Steve L.
> http://www.troubleshooters.com
> removed_email_address@domain.invalid
>
>
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.
slitt (Guest)
on 2005-12-09 23:01
(Received via mailing list)
On Friday 09 December 2005 01:22 pm, Eric L. wrote:
> 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.

Thanks Eric,

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 :-)

Thanks

SteveT

Steve L.
http://www.troubleshooters.com
removed_email_address@domain.invalid
dandiebolt (Guest)
on 2005-12-09 23:13
(Received via mailing list)
Take a look at Octave - a Matlab Clone:

  http://www.octave.org/
blargity (Guest)
on 2005-12-09 23:17
(Received via mailing list)
On Friday 09 December 2005 14:58, Steve L. wrote:
> gnuplot. No joy -- gnuplot's interpolation between points is stupid -- all
> 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_...

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?
dandiebolt (Guest)
on 2005-12-09 23:25
(Received via mailing list)
>Use the GNU Graph utility.

  Octave uses GNU Graphics and it can solve your implicit equations for
points.
perrin (Guest)
on 2005-12-10 00:06
(Received via mailing list)
On Sat, Dec 10, 2005 at 06:16:55AM +0900, Kevin B. wrote:
> 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 P. [ 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.
blargity (Guest)
on 2005-12-11 07:23
(Received via mailing list)
On Friday 09 December 2005 16:04, Chad P. wrote:
> > 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 (Guest)
on 2005-12-11 17:36
(Received via mailing list)
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.
blargity (Guest)
on 2005-12-11 18:08
(Received via mailing list)
On Sunday 11 December 2005 09:07, Larry W. 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.
Sky Y. (Guest)
on 2005-12-11 22:27
(Received via mailing list)
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
Jacob Quinn S. (Guest)
on 2005-12-12 05:33
(Received via mailing list)
IO::popen("myprogg", "w") do |pipe|
pipe.puts("Look at me pass stuff through an interprocess pipe!")
end
This topic is locked and can not be replied to.