File: cossin.rb

package info (click to toggle)
ruby-gsl 2.1.0.3%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,604 kB
  • sloc: ansic: 62,050; ruby: 15,845; sh: 19; makefile: 10
file content (35 lines) | stat: -rwxr-xr-x 772 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env ruby
#begin
#  require 'rubygems'
#  require_gem "gnuplot"         # Try using rubygem
#ensure
  require 'gnuplot'             # No gem, use traditional require
#end

require "gsl"

# Add the to_gplot method to Vector since its not already built in.  This
# might be worthwhile adding to the core GSL stuff.

x = GSL::Vector.linspace(0, 2*M_PI, 100)
s = Sf::sin(x)
c = Sf::cos(x)

# Now generate the actual plot
Gnuplot::open do |gp|
  Gnuplot::Plot.new( gp ) do |plot|

    plot.title "GSL plotting example"
    plot.data = [
      Gnuplot::DataSet.new( [x, c] ) { |ds|
        ds.title = "cos(x)"
        ds.with = "lines"
      },
      Gnuplot::DataSet.new( [x, s] ) { |ds|
        ds.title = "sin(x)"
        ds.with = "lines"
      }
    ]
  end
end