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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
David Goodmanson
am 17 Feb. 2024
Bearbeitet: David Goodmanson
am 17 Feb. 2024
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
Siehe auch
Kategorien
Mehr zu PDE Solvers finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!