Small Satellites

Home » Posts tagged 'Straight Line Fit'

Tag Archives: Straight Line Fit

Best Fit Solution,Straight Line Fit

%https://smallsat.wordpress.com/

clear all
clc
T = [0,20,100,100,200,400,400,800,1000,1200,1400,1600];
R = [10.96,10.72,14.1,14.85,17.9,25.4,26,40.3,47,52.7,58,63];
plot(T,R,'r*');
title('Straight Line Fit');
xlabel('Temperature (deg C)');
ylabel('Resistivity (Ohm cm)');
sy = 0;
sx = 0;
sxy = 0;
sx2 = 0;
n = 12;
for i=1:n
sy = sy +R(i);
sx = sx + T(i);
sxy = sxy + T(i)*R(i);
sx2 = sx2 + T(i)*T(i);
end
a = (sy*sx2-sx*sxy)/(n*sx2-sx^2);
b = (n*sxy-sx*sy)/(n*sx2-sx^2);
fprintf('\n\n Best Fit Coefficients')
fprintf('\n x = %6.4f T + %6.4f \n',b,a)
cm_fit =a+b*T;
hold on;
plot(T,cm_fit,'r');
legend('Data Points','Best Fit Solution','location','northwest');
 Best Fit Coefficients
 x = 0.0337 T + 11.4695

 

Published with MATLABĀ® 7.10

Advertisements
%d bloggers like this: