Created
November 18, 2011 10:52
-
-
Save syrusakbary/1376147 to your computer and use it in GitHub Desktop.
Problema 1 de la hoja 3 de Teoría de Errores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [t,y]=carga(fichero) | |
[t,y] = textread(fichero, '%f %f'); | |
t = t'; | |
y = y'; | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 66.7 | |
4 71.0 | |
10 76.3 | |
15 80.6 | |
21 85.7 | |
29 92.9 | |
36 99.4 | |
51 113.6 | |
68 125.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% t = [0 4 10 15 21 29 36 51 68] | |
% y = [66.7 71.0 76.3 80.6 85.7 92.9 99.4 113.6 125.1] | |
[t,y] = carga('nombre del fichero') | |
y_est = rectaregresion(t,y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rectaregresion=rectaregresion(t,y) | |
m = length(t); | |
At=[t;ones(1,m)]; | |
A = At'; | |
r = rank(A); | |
x_est = (At*A)^-1*At*y'; | |
a = x_est(1); | |
b = x_est(2); | |
v_c = []; | |
y_ajust = []; | |
for i=1:m | |
y_ajust(i) = a*t(i)+b; | |
vi = y_ajust(i)-y(i); | |
v_c(i) = vi^2; | |
end | |
error = sum(v_c); | |
rectaregresion=y_ajust; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment