Sha256: 6d98636545ce45029ea164bf75cd7459c371e3232846f353524d13474d235114

Contents?: true

Size: 703 Bytes

Versions: 22

Compression:

Stored size: 703 Bytes

Contents

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

f = GSL::Function.alloc { |x|
  GSL::pow(x, 1.5)
}

printf("f(x) = x^(3/2)\n");

x = 2.0
result, abserr,status = f.diff_central(x)
printf("x = 2.0\n");
printf("f'(x) = %.10f +/- %.5f\n", result, abserr);
printf("exact = %.10f\n\n", 1.5 * Math::sqrt(2.0));

x = 0.0
result, abserr, status = f.diff_forward(x)
printf("x = 0.0\n");
printf("f'(x) = %.10f +/- %.5f\n", result, abserr);
printf("exact = %.10f\n", 0.0);

f2 = GSL::Function.alloc { |x, a| Math::exp(a*x) }

f2.set_params(2)
p f2.diff_central(0)

f2.set_params(3)
p f2.diff_central(0)

f2.set_params(123)
p f2.diff_central(0)

p GSL::Diff.central(f2, 0)
p GSL::Diff.forward(f2, 0)
p GSL::Diff.backward(f2, 0)

Version data entries

22 entries across 22 versions & 4 rubygems

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