Total Least squares error help. I tried a couple different things here, but i'm not exactly sure how to do a total least squares error. The numbers aren't making sense to me.
1 次查看(过去 30 天)
显示 更早的评论
clear all
% A represents the sample measured in days
A = [1, 0; 1, 1; 1, 2; 1, 3; 1, 4; 1, 5; 1, 6; 1, 7]
% b represents the amount of radium measured
b = [100; 82.7; 68.3; 56.5; 46.7; 38.6; 31.9; 26.4]
% Least Squares
c = lsqr(A,log(b))
g = A.'*A
rhs = A.'*log(b);
x = g\rhs
thalf = -x(2)^-1*log(2)
m0 = exp(x(1))
m = @(t) m0*exp(x(2)*t);
predictionvalues = m([0, 1, 2, 3, 4, 5, 6, 7]);
squareddifferences = (predictionvalues - b).^2;
totalerror = sum(squareddifferences)
t = [0, 1, 2, 3, 4, 5, 6, 7];
plot(t, x(1) + x(2)*t, t, log(b),'o')
%%plot(t, abs(exp(y_approx(t)-b)))
xlabel("t")
ylabel("error")
2 个评论
回答(1 个)
David Goodmanson
2024-2-17
编辑:David Goodmanson
2024-2-17
Hi Rian,
the problem is that b is a column vector, but predictionvalues is a row vector. Using
predictionvalues = m([0, 1, 2, 3, 4, 5, 6, 7])'; % column vector
squareddifferences = (predictionvalues - b).^2;
totalerror = sum(squareddifferences)
totalerror =
0.0033
although depending on circumstances, you may want to use sqrt(totalerror/8), the rms value, as the final result
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 PDE Solvers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!