[Scilab-users] Problem using datafit()
Federico Miyara
fmiyara at fceia.unr.edu.ar
Wed Sep 8 00:17:42 CEST 2021
Dear all,
I have a problem using datafit() to adjust the parameters of a model.
The script below has four parts. The first one actually is a synthesis
of the data I'm working with. It just creates the data (logf0, Te) to model.
The second part introduces the function g(x, p) to model the data.
Part three creates the "gap" function required for datafit(). It does so
in two alternative ways selected with the variable option. If option =
1, the definition of the gap function is given inside the body of that
function. If option = 2, it uses the model function previously created.
Finally, part 4 addresses the fitting procedure.
My problem is that with option = 1, it works fine, but when option = 2
it halts with the following error:
--> [P, err] = datafit(G, Z, po)
at line 8 of function G
at line 16 of function costf
at line -12 of function optim
at line 243 of function datafit ( C:\Program
Files\scilab-6.1.1\modules\optimization\macros\datafit.sci line 255 )
Invalid index.
--> toc
ans =
0.6467990
The normal time to do the full fitting is about 40 s. The time of the
aborted process is 0.64 s, long enough to have done some iterations,
which is baffling. I tried to see inside the datafit() source but
frankly I don't understand what may be happening.
May be somebody with more experience in the use of this function can
give a hint on what's going on...
Regards,
Federico Miyara
// 1 Data to approximate (Te = F(logf0))
logf = linspace(2.3025851, 9.9010847, 7)
Telogf = [ 0.0446706 0.0225414 0.0147556 0.0055733 0.010994 ...
0.0189552 0.0277157]
d = [-0.0338451 -0.0073327 -0.0076891 -0.0021065 0.0072043 ...
0.0049894 0.0124498]
logf0 = log(10*10.^(0:0.005:3.3))
Te = interp(logf0, logf, Telogf, d);
// 2 Analytic model
function y=g(x, p)
y = p(1) + p(2)*abs(x).^p(3) - p(4)*exp(-p(5)*x.^2);
endfunction
// 3 Function to minimize
// (Gap or difference between data and model)
function e=G(p, z)
option = 1
select option
case 1
gg = p(1) + p(2)*abs(z(1)).^p(3) - p(4)*exp(-p(5)*z(1).^2);
e = z(2) - gg;
case 2
e = z(2) - g(z(1), p)
end
endfunction
// 4 Parameter algorithm adjustment
Z = [logf0 - 6.2515185; Te];
po = [0.005 -0.00013 4 0.01 1.7]
tic
[P, err] = datafit(G, Z, po)
toc
--
El software de antivirus Avast ha analizado este correo electrónico en busca de virus.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20210907/bedf12dc/attachment.htm>
More information about the users
mailing list