Dear all, I am having a reoccuring issue with leasqr, I am trying to interpolate data with a weibull function [something like y = e^((a*t)^k)].
This is my data
A =
0.00000 0.00000 0.00000
22.50000 0.90672 1.10453
47.00000 1.02958 1.26305
72.16667 1.11205 1.46428
95.50000 1.18885 1.57736
166.50000 1.34828 1.88047
192.25000 1.39940 1.94198
216.00000 1.45110 2.01961
262.50000 1.51369 2.14295
334.50000 1.60073 2.32114
385.00000 1.65601 2.42147
431.00000 1.69672 2.50011
504.00000 1.74113 2.58324
552.00000 1.90475 2.65936
603.00000 1.79520 2.71121
674.00000 1.84116 2.79580
720.00000 1.86893 2.66708
863.00000 1.91990 2.93466
934.66666 1.94194 2.98087
1008.00000 1.96009 3.01555
And this is my code
A = dlmread(“data.txt”);
##A = A([2:end],:);
xi = A(:,1);
yi = A(:,2);
qrfunc = @(xi, p) yi(end) - yi(end)*exp(p(1).*xi).^p(2);
p = [1, 0.4];
wt = linspace(1,1,length(yi))’;
dp = [.001; .001]; % bidirectional numeric gradient stepsize
dFdp = “dfdp”; % function for gradient (numerical)
[f, pint, kvg, iter, corp, covp, covr, stdresid, Z, r] = leasqr(xi, yi, p, qrfunc, 0.001, 200, wt, dp, dFdp, [-Inf, Inf; 0.74, 0.76]);
There are a few things that puzzle me.
First, I am getting the error
error: svd: cannot take SVD of matrix containing Inf or NaN values
error: called from
lm_svd at line 207 column 17
leasqr at line 660 column 25
data at line 13 column 56
I do not understand. There are no Inf or NaN values, I thought? Ok, I can work around by scaling xi and yi such that their maximum is 1 (backscale after the interpolation):
a = max(xi);
b = max(yi);
xi = xi/a;
yi = yi/b;
and
xinterp = linspace(xi(1), xi(end),40)’;
yinterp = yi(end) - yi(end)exp(pint(1).xinterp).^pint(2);
plot(axi, byi,‘bo’, axinterp, byinterp)
legend(‘Data’, ‘Interpolation’, ‘location’, ‘southeast’)
Then the code runs through, but the interpolation is unsatisfying. Why does the code require the maximum of xi and yi to be 1 (or any other number perhaps)? And why is the interpolation not so good? I mean, the chosen function can interpolate the data much better in terms of smaller r.
The second thing I noticed is that my bounds are not respected.
I would appreciate any input with regards to the “scaling requirement” and what can be changed such that the bounds are respected.
Please let me know if any information is missing.