Dear all,
I have to determine the minima of a multiparameter mathematical
function
numerically.
I try to use the simplex method, as implemented in Ruby-Gsl, to do
this.
Below is some code from an example as given in the documentation of
Ruby/Gsl.
However, when I run this on Cygwin (Windows XP), I get a segmentation
fault
from the line where the parameters are set, whereas in Fedora, I am not
allowed
to allocate even the function to minimize.
Has anybody had this problem before ? Has anybody some self-written
code
for multidimensional minimization (preferably simplex method)?
Thank you very much in advance,
Best regards
Axel
#!/usr/bin/env ruby
require(“gsl”)
include GSL::MultiMin
np = 2
my_f = Proc.new { |v, params|
x = v[0]; y = v[1]
p0 = params[0]; p1 = params[1]
10.0*(x - p0)(x - p0) + 20.0(y - p1)*(y - p1) + 30.0
}
my_func = Function.alloc(my_f, np) # ERROR in Fedora: undefined
method
`alloc’ for GSL::MultiMin::FMinimizer:Class (NoMethodError)
my_func.set_params([1.0, 2.0]) # parameters: SEGMENTATION fault in
Fedora.
x = Vector.alloc([5, 7])
ss = Vector.alloc(np)
ss.set_all(1.0)
minimizer = FMinimizer.alloc(“nmsimplex”, np)
minimizer.set(my_func, x, ss)
iter = 0
begin
iter += 1
status = minimizer.iterate()
status = minimizer.test_size(1e-2)
if status == GSL::SUCCESS
puts("converged to minimum at")
end
x = minimizer.x
printf("%5d ", iter);
for i in 0…np do
printf("%10.3e ", x[i])
end
printf(“f() = %7.3f size = %.3f\n”, minimizer.fval, minimizer.size);
end while status == GSL::CONTINUE and iter < 100