## Copyright (C) 2020 Jens
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see
## .
## -*- texinfo -*-
## @deftypefn {} {@var{retval} =} to_param (@var{input1}, @var{input2})
##
## @seealso{}
## @end deftypefn
## Author: Jens
## Created: 2020-10-07
function p = to_param(x, pmin, pmax, B, k, pcenter, scenter)
if (pmin == pmax)
pmax += 1E-9;
end
if (k == 0)
k = 1E-9;
end
if ((pcenter < pmin) || (pcenter > pmax))
pcenter = pmax*scenter + pmin*(1-scenter);
end
x = min(1, max(0, x));
kc = 1/(B^k-1);
p = [];
for n=1:length(x);
s = x(n);
if (s < scenter)
s = (scenter-s)/scenter;
ks = -(pcenter-pmin);
else
s = (-scenter+s)/(1-scenter);
ks = (pmax-pcenter);
end
if (B == 1)
p = [p pcenter + ks*kc*s];
else
p = [p pcenter + ks*kc*(B.^(k*s)-1)];
end
end
endfunction