Sha256: d73eb5e6b0ca6ba5690d6c9d5a1f0251a10e6edfb0e2274daeac08bf6dbee199

Contents?: true

Size: 695 Bytes

Versions: 22

Compression:

Stored size: 695 Bytes

Contents

#!/usr/bin/env ruby
require("gsl")

if ARGV.size != 1
  puts("Usage: integrate n\nn is the number of quadrature points.")
  exit
end

Q = ARGV[0].to_i
if Q < 1
  puts("Usage: integrate n\nn is the number of quadrature points.")
  exit
end

def fun(x)
  Math::cos(3.0*x)
end

def dfun(x)
  -3.0*Math::sin(3.0*x)
end

f = GSL::Vector.alloc(4*Q)
xp = GSL::Vector.linspace(0.1, 0.9, 9)

quad = Jac::Quadrature.alloc(Q)
quad.zwd(Jac::GJ, 0.0, 0.0)
quad.interpmat_alloc(xp)

for i in 0...Q do
  f[i] = fun(quad.x[i])
end

fout = quad.interpolate(f)

printf("X \t f(x) \t Error\n");

for i in 0...xp.size do
  printf("%f \t %f \t %e\n", xp[i], fout[i], fout[i] - fun(xp[i]));
end

quad.interpmat_free

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
gsl-2.1.0.3 examples/jacobi/interp.rb
gsl-2.1.0.2 examples/jacobi/interp.rb
gsl-2.1.0.1 examples/jacobi/interp.rb
gsl-2.1.0 examples/jacobi/interp.rb
gsl-1.16.0.6 examples/jacobi/interp.rb
rb-gsl-1.16.0.5 examples/jacobi/interp.rb
rb-gsl-1.16.0.4 examples/jacobi/interp.rb
rb-gsl-1.16.0.3 examples/jacobi/interp.rb
rb-gsl-1.16.0.3.rc1 examples/jacobi/interp.rb
gsl-nmatrix-1.15.3.2 examples/jacobi/interp.rb
gsl-nmatrix-1.15.3.1 examples/jacobi/interp.rb
rb-gsl-1.16.0.2 examples/jacobi/interp.rb
rb-gsl-1.16.0.1 examples/jacobi/interp.rb
rb-gsl-1.16.0 examples/jacobi/interp.rb
rb-gsl-1.15.3.2 examples/jacobi/interp.rb
rb-gsl-1.15.3.1 examples/jacobi/interp.rb
blackwinter-gsl-1.15.3.2 examples/jacobi/interp.rb
gsl-nmatrix-1.15.3.0 examples/jacobi/interp.rb
gsl-1.15.3 examples/jacobi/interp.rb
gsl-1.14.7 examples/jacobi/interp.rb