Skip to content

Instantly share code, notes, and snippets.

@giraffesyo
Created February 22, 2018 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giraffesyo/73621c84df20f570298bd6906197fd54 to your computer and use it in GitHub Desktop.
Save giraffesyo/73621c84df20f570298bd6906197fd54 to your computer and use it in GitHub Desktop.
clear *; close all; clc;
x = [2,3,2,3]';
y = [4, 6, 6, 8]';
plot(x,y, '*'), hold on;
axis([0,4,0,10]);
sx = sum(x);
sy = sum(y);
sxx = sum(x.^2);
sxy = sum(x.*y);
A = [size(x, 1) sx
sx, sxx];
B = [sy sxy]';
C = A\B
xn = 0:0.1:10;
yn = C(1) + C(2)*xn;
plot(xn, yn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment