필터 지우기
필터 지우기

How to solve "Rank deficient, rank = 7, tol = 6.169247e+09." in nlinfit

조회 수: 3 (최근 30일)
宏宇
宏宇 2022년 9월 3일
편집: Torsten 2022년 9월 4일
When the authors use nlinfit to fit the data, they consistently show a rank deficit. Is it because of the initial value setting?
clear;clc
format long
T=[33.2131 42.7043 48.8077 53.6257 57.7245 29.4295 33.0460 35.9052 38.3089...
42.8741 48.9372 53.7321 57.8148 61.4343 64.7215 67.7579 70.5979 73.2786...
75.8258 78.2613 80.5992 82.8526 85.0322 87.1452 89.1993 91.2015 93.1555...
95.0632 96.9314 98.7621 62.3556 71.5780 79.2821 86.1019 92.3337 29.1443...
32.8341 35.7294 38.1597 42.7520 48.8448 53.6546 57.7485 61.3737 64.6661];
% T = xlsread ('T.xlsx','Sheet1');
dT=[12.0335 6.9579 5.2636 4.3835 3.8312 4.0968 3.1274 2.5777 2.2236...
6.9005 5.2363 4.3646 3.8176 3.4396 3.1554 2.9392 2.7668 2.6229...
2.5022 2.3990 2.3119 2.2316 2.1666 2.1046 2.0501 1.9998 1.9544...
1.9143 1.8760 1.8412 10.2210 8.2580 7.1899 6.5020 6.0173 4.1877...
3.1736 2.6077 2.2428 6.9371 5.2576 4.3758 3.8264 3.4432 3.1618];
% dT = xlsread ('dT.xlsx','Sheet1');
Q_0=[90.26328 90.66839 90.47602 90.42722 90.32820 22.95437 22.88944 22.83842 22.81414...
90.65877 90.48850 90.36904 90.26715 90.19663 90.04881 89.98361 89.96804 89.88941...
89.86651 89.73939 89.73409 89.62329 89.61274 89.55704 89.55862 89.49705 89.42748...
89.39781 89.35200 89.39452 274.4339 273.7179 273.2521 272.9280 272.6679 22.89278...
22.88800 22.85388 22.80479 90.60546 90.48330 90.36902 90.26860 90.16708 90.09233];
% Q_0 = xlsread ('Q_0.xlsx','Sheet1');
T1=(2*T-dT)./2;
T2=T1+dT;
%Q_0=(T2-T)*C(1)+(T2.^2-T.^2)*C(2)+(T2.^3-T.^3)*C(3)+(T2.^4-T.^4)*C(4)+(T2.^5-T.^5)*C(5)...
% +(T2.^6-T.^6)*C(6)+(T2.^7-T.^7)*C(7)+(T2.^8-T.^8)*C(8)+(T2.^9-T.^9)*C(9)...
% +(T2.^10-T.^10)*C(10)+(T2.^11-T.^11)*C(11)+(T2.^12-T.^12)*C(12);
Y=Q_0';
X=[T1;T2]';
C0 = [1.070179528057E1,-4.72169505856E-1 ,0.01,1E-6,-1E-6,1E-8,-1E-10,1E-13,-1E-15,1E-18,-1E-21,1E-24]';
Z=dT.\Q_0;
fun=@(C,X) (C(1)*(X(:,2)-X(:,1))+C(2)*(X(:,2).^2-X(:,1).^2)+C(3)*(X(:,2).^3-X(:,1).^3)+...
C(4)*(X(:,2).^4-X(:,1).^4)+C(5)*(X(:,2).^5-X(:,1).^5)+C(6)*(X(:,2).^6-X(:,1).^6)+...
C(7)*(X(:,2).^7-X(:,1).^7)+C(8)*(X(:,2).^8-X(:,1).^8)+C(9)*(X(:,2).^9-X(:,1).^9)+...
C(10)*(X(:,2).^10-X(:,1).^10)+C(11)*(X(:,2).^11-X(:,1).^11)+C(12)*(X(:,2).^12-X(:,1).^12));
%nlinfit
[C,r,J]=nlinfit(X,Y,fun,C0)
plot(T,Z,'r*');
The C values obtained from the same data in the literature are shown in the following figure:
  댓글 수: 4
宏宇
宏宇 2022년 9월 3일
Q_0 is not represented by simple T2 and T1, but also includes power and parameters.
Star Strider
Star Strider 2022년 9월 3일
@John D'ErricoThank you!
@宏宇 — The regression is on (X,Y) so that is what I plotted —
[C,r,J]=nlinfit(X,Y,fun,C0)
However the reported plot is —
Z=dT.\Q_0;
plot(T,Z,'r*');
so I have absolutely no idea what is being done here.
The function in this Comment has just now appeared. I assume that this is the ‘Q_0’ vector and it has already been calculated. If not, there is no further calculation for it, and to complicate all this, ‘C’ is being calculated from ‘Q_0’ (being ‘Y’) so this becomes even more confusing.
I just cannot follow whatever this is doing. At least more explanation is necessary. There might be something of interest in all these data, and they have just not been presented or analysed correctly.
.

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2022년 9월 3일
편집: Torsten 2022년 9월 3일
There must be something that you misunderstood in the article.
The problem from above is a linear fitting problem for the vector C. The solution can be obtained without nlinfit as below, but the problem with the rank-deficiency remains.
clear;clc
format long
T=[33.2131 42.7043 48.8077 53.6257 57.7245 29.4295 33.0460 35.9052 38.3089...
42.8741 48.9372 53.7321 57.8148 61.4343 64.7215 67.7579 70.5979 73.2786...
75.8258 78.2613 80.5992 82.8526 85.0322 87.1452 89.1993 91.2015 93.1555...
95.0632 96.9314 98.7621 62.3556 71.5780 79.2821 86.1019 92.3337 29.1443...
32.8341 35.7294 38.1597 42.7520 48.8448 53.6546 57.7485 61.3737 64.6661];
% T = xlsread ('T.xlsx','Sheet1');
dT=[12.0335 6.9579 5.2636 4.3835 3.8312 4.0968 3.1274 2.5777 2.2236...
6.9005 5.2363 4.3646 3.8176 3.4396 3.1554 2.9392 2.7668 2.6229...
2.5022 2.3990 2.3119 2.2316 2.1666 2.1046 2.0501 1.9998 1.9544...
1.9143 1.8760 1.8412 10.2210 8.2580 7.1899 6.5020 6.0173 4.1877...
3.1736 2.6077 2.2428 6.9371 5.2576 4.3758 3.8264 3.4432 3.1618];
% dT = xlsread ('dT.xlsx','Sheet1');
Q_0=[90.26328 90.66839 90.47602 90.42722 90.32820 22.95437 22.88944 22.83842 22.81414...
90.65877 90.48850 90.36904 90.26715 90.19663 90.04881 89.98361 89.96804 89.88941...
89.86651 89.73939 89.73409 89.62329 89.61274 89.55704 89.55862 89.49705 89.42748...
89.39781 89.35200 89.39452 274.4339 273.7179 273.2521 272.9280 272.6679 22.89278...
22.88800 22.85388 22.80479 90.60546 90.48330 90.36902 90.26860 90.16708 90.09233];
% Q_0 = xlsread ('Q_0.xlsx','Sheet1');
T1=(2*T-dT)./2;
T2=T1+dT;
%Q_0=(T2-T)*C(1)+(T2.^2-T.^2)*C(2)+(T2.^3-T.^3)*C(3)+(T2.^4-T.^4)*C(4)+(T2.^5-T.^5)*C(5)...
% +(T2.^6-T.^6)*C(6)+(T2.^7-T.^7)*C(7)+(T2.^8-T.^8)*C(8)+(T2.^9-T.^9)*C(9)...
% +(T2.^10-T.^10)*C(10)+(T2.^11-T.^11)*C(11)+(T2.^12-T.^12)*C(12);
Y=Q_0';
X=[T1;T2]';
A = [X(:,2)-X(:,1),X(:,2).^2-X(:,1).^2,X(:,2).^3-X(:,1).^3,X(:,2).^4-X(:,1).^4,X(:,2).^5-X(:,1).^5,...
X(:,2).^6-X(:,1).^6,X(:,2).^7-X(:,1).^7,X(:,2).^8-X(:,1).^8,X(:,2).^9-X(:,1).^9,X(:,2).^10-X(:,1).^10,...
X(:,2).^11-X(:,1).^11];
b = Y;
C = A\b
Warning: Rank deficient, rank = 6, tol = 4.797514e+07.
C = 11×1
1.0e-06 * 0 0 0 0 0 0.245847633266853 -0.011686042243299 0.000238193643051 -0.000002533319987 0.000000013833084
  댓글 수: 4
宏宇
宏宇 2022년 9월 4일
Thanks Torsten
After adjustment, the fitting of yesterday was relatively successful, but after continuing to increase the data of T, dT and Q0, the fitting of C failed again. So not sure if you have a better way to fit the data.
Or use the fitting method you used yesterday, and still can't get a good fit.
clear;clc
format long
b=xlsread('shuju.xlsx');
T=b(:,1);
dT=b(:,2);
Q_0=b(:,3);
T1=(2*T-dT)./2;
T2=T1+dT;
Y=Q_0;
X=[T1 T2];
C0 = [1.070179528057e1;-4.72169505856e-1;9.985458119236e-3;...
3.443201289415e-6;-1.486069268038e-6;1.901352098615e-8;...
-1.300438485128e-10;5.60742395948e-13;-1.572000054992e-15;...
2.789945522377e-18;-2.854347532609e-21;1.284323931260e-24]';
%C0 is C0 in the literature, but it is impossible to know in the actual process,
% so how to obtain C0.
Z=Q_0./dT;
fun=@(C,X) (C(1)*(X(:,2)-X(:,1))+C(2)*(X(:,2).^2-X(:,1).^2)+C(3)*(X(:,2).^3-X(:,1).^3)+...
C(4)*(X(:,2).^4-X(:,1).^4)+C(5)*(X(:,2).^5-X(:,1).^5)+C(6)*(X(:,2).^6-X(:,1).^6)+...
C(7)*(X(:,2).^7-X(:,1).^7)+C(8)*(X(:,2).^8-X(:,1).^8)+C(9)*(X(:,2).^9-X(:,1).^9)+...
C(10)*(X(:,2).^10-X(:,1).^10)+C(11)*(X(:,2).^11-X(:,1).^11)+C(12)*(X(:,2).^12-X(:,1).^12));
[C,r,J]=nlinfit(X,Y,fun,C0)
Q_2=0;
for i=1:1:12
Q_2=Q_2+(T2.^i-T1.^i)*C(i);
end
S=dT.\Q_2;
plot(T,Z,'r*',T,S,'kx');
Torsten
Torsten 2022년 9월 4일
Fits are done for that they can be used for other measurement data as well. So I don't understand why you fit the parameters again. But if you like ...
b = [33.2131 12.0335 90.26328
42.7043 6.9579 90.66839
48.8077 5.2636 90.47602
53.6257 4.3835 90.42722
57.7245 3.8312 90.3282
29.4295 4.0968 22.95437
33.046 3.1274 22.88944
35.9052 2.5777 22.83842
38.3089 2.2236 22.81414
42.8741 6.9005 90.65877
48.9372 5.2363 90.4885
53.7321 4.3646 90.36904
57.8148 3.8176 90.26715
61.4343 3.4396 90.19663
64.7215 3.1554 90.04881
67.7579 2.9392 89.98361
70.5975 2.7668 89.96804
73.2786 2.6229 89.88941
75.8258 2.5022 89.86651
78.2613 2.399 89.73939
80.5992 2.3119 89.73409
82.8526 2.2316 89.62329
85.0322 2.1666 89.61274
87.1452 2.1046 89.55704
89.1993 2.0501 89.55862
91.2015 1.9998 89.49705
93.1555 1.9544 89.42748
95.0632 1.9143 89.39781
96.9314 1.876 89.352
98.7621 1.8412 89.29452
62.3556 10.221 274.4339
71.578 8.258 273.7197
79.2821 7.1899 273.2521
86.1019 6.502 272.928
92.3337 6.0173 272.6679
29.1443 4.1877 22.95278
32.8341 3.1736 22.888
35.7294 2.6077 22.85388
38.1597 2.2428 22.80479
42.752 6.9371 90.60546
48.8448 5.2576 90.4833
53.6546 4.3758 90.36902
57.7485 3.8264 90.2686
61.3737 3.4432 90.16708
64.6661 3.1618 90.09233
300.294 2.066 171.11
302.419 2.061 171.13
303.809 0.528 43.93
275.05 0.549 44.73
275.881 1.091 88.8
278.5 4.129 336.76
279.032 4.446 362.53
283.489 4.416 361.6
287.955 4.414 362.85
292.433 4.387 362.01
296.923 4.385 362.77
295.532 4.397 363.52
300.004 4.357 361.64
304.486 4.357 362.6
309.774 4.32 361.27
314.12 4.301 360.81
318.482 4.278 360.32
309.649 4.291 358.79
314.3 4.298 361.24
319.013 4.286 361.95
273.211 4.535 368.33
277.724 4.472 364.76
282.215 4.462 365.31
286.704 4.442 365.09
291.192 4.423 365.02
295.681 4.406 364.89
300.167 4.383 364.34
304.708 4.369 364.55
309.206 4.346 363.82
314.458 5.802 487.91
319.745 4.306 363.53
127.08 4.659 276.68
131.608 4.566 276.97
136.098 4.47 276.91
142.318 8.114 515.94
150.056 7.443 487.31
131.622 1.69 102.45
134.09 3.322 203.83
137.347 3.266 203.25
139.657 1.623 102.05
142.81 4.755 302.82
147.463 4.647 301.24
152.806 6.141 405.71
161.128 5.143 348.38
167.386 7.49 516.45
174.725 7.355 517.13
175.502 3.793 267.16
179.197 3.742 265.77
182.608 3.703 264.77
186.241 3.686 265.63
188.966 1.899 137.84
190.803 1.878 136.84
194.4 5.425 397.55
199.723 5.372 397.3
202.396 7.062 524.84
206.831 1.954 146.42
208.722 1.96 147.17
212.843 6.685 505.29
220.458 8.686 664.24
226.417 3.377 260.27
229.716 3.365 260.77
235.624 8.567 668.38
232.939 5.909 459.71
238.781 5.872 459.82
244.575 5.807 457.64
250.293 5.808 460.72
256.055 5.756 459.52
261.79 5.723 459.75
267.5 5.665 457.91
273.202 5.657 459.37
277.804 5.639 459.7
283.507 5.594 458.47
289.44 5.567 458.77
295.144 5.529 457.9
87.956 4.522 193.92
92.45 4.502 203.72
96.923 4.469 212.18
101.371 4.456 220.68
105.801 4.442 228.64
110.252 4.499 239.77
114.693 4.503 247.67
119.179 4.519 255.8
123.684 4.549 264.42
128.143 4.435 264.04
276.822 5.616 457.34
282.678 5.617 459.8
276.345 5.642 459.05
281.862 5.606 458.25
276.552 5.612 456.82
282.382 5.598 458.11
275.701 5.604 455.7
281.212 5.61 458.36];
T=b(:,1);
dT=b(:,2);
Q_0=b(:,3);
T1=(2*T-dT)./2;
T2=T1+dT;
Y=Q_0;
X=[T1 T2];
C0 = [1.070179528057e1;-4.72169505856e-1;9.985458119236e-3;...
3.443201289415e-6;-1.486069268038e-6;1.901352098615e-8;...
-1.300438485128e-10;5.60742395948e-13;-1.572000054992e-15;...
2.789945522377e-18;-2.854347532609e-21;1.284323931260e-24].';
%C0 is C0 in the literature, but it is impossible to know in the actual process,
% so how to obtain C0.
Z=Q_0./dT;
A = [X(:,2)-X(:,1),X(:,2).^2-X(:,1).^2,X(:,2).^3-X(:,1).^3,X(:,2).^4-X(:,1).^4,X(:,2).^5-X(:,1).^5,...
X(:,2).^6-X(:,1).^6,X(:,2).^7-X(:,1).^7,X(:,2).^8-X(:,1).^8,X(:,2).^9-X(:,1).^9,X(:,2).^10-X(:,1).^10,...
X(:,2).^11-X(:,1).^11,X(:,2).^12-X(:,1).^12];
b = Y;
format long g
C = lsqnonlin(@(C)A*C-b,C0.')
Local minimum possible. lsqnonlin stopped because the size of the current step is less than the value of the step size tolerance.
C = 12×1
10.70179528057 -0.472169505856 0.009985458119236 3.443201289415e-06 -1.486069268038e-06 1.901352098615e-08 -1.30043848512968e-10 5.60742386224611e-13 -1.57219671585905e-15 2.79170998059763e-18
norm(A*C-b)
ans =
3.62409076105991
%fun=@(C,X) (C(1)*(X(:,2)-X(:,1))+C(2)*(X(:,2).^2-X(:,1).^2)+C(3)*(X(:,2).^3-X(:,1).^3)+...
% C(4)*(X(:,2).^4-X(:,1).^4)+C(5)*(X(:,2).^5-X(:,1).^5)+C(6)*(X(:,2).^6-X(:,1).^6)+...
% C(7)*(X(:,2).^7-X(:,1).^7)+C(8)*(X(:,2).^8-X(:,1).^8)+C(9)*(X(:,2).^9-X(:,1).^9)+...
% C(10)*(X(:,2).^10-X(:,1).^10)+C(11)*(X(:,2).^11-X(:,1).^11)+C(12)*(X(:,2).^12-X(:,1).^12));
%[C,r,J]=nlinfit(X,Y,fun,C0);
%norm(fun(C,X)-Y)
Q_2 = A*C;
S=dT.\Q_2;
plot(T,Z,'r*',T,S,'kx');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Least Squares에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by