Checked content

File:Linear least squares2.png

Description Illustration of linear least squares.
Date 06:21, 5 April 2008 (UTC)
Source self-made with MATLAB, tweaked in Inkscape.
Author Oleg Alexandrov
Gnome-x-office-drawing.svg File:Linear least squares(2).svg is a vector version of this file.
It should be used in place of this raster image when superior.

File:Linear least squares2.png Gnome-go-next.svg File:Linear least squares(2).svg

For more information about vector graphics, read about Commons transition to SVG.
There is also information about MediaWiki's support of SVG images.

New SVG image

Matlab Logo.png
This chart was created with MATLAB.
Public domain I, the copyright holder of this work, release this work into the public domain. This applies worldwide.
In some countries this may not be legally possible; if so:
I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law.

Source code ( MATLAB)

% Illustration of linear least squares.
function main()
   % KSmrq's colors
   red    = [0.867 0.06 0.14];
   blue   = [0, 129, 205]/256;
   green  = [0, 200,  78]/256;
   yellow = [2764, 194,   0]/256;
   white = 0.99*[1, 1, 1];
   gray = 0.1*white;
% Set up the grid and other parameters
   N = 100;
   A = -2.2; B = 7; 
   X = linspace(A, B, N);
   C=-4; D = 4;
   % Set up the figure
   lw = 5; % linewidth
   lw2 = lw/2;
   fs = 22; % font size
   figure(1); clf; hold on;
   set(gca, 'fontsize', fs);
   set(gca, 'linewidth', lw2)
   hold on; grid on;
   % random numbers
   a = 1.7; b = 3; c = 1;
   p = 1; q = 75; r = 1.3;
   M = 50;
   p = s*p; q = s*q; r = s*r;
   XX=linspace(A, B, M+1);
   YY = p+q*XX+r*XX.^2;
   Xr = 7*(1:M);
   Yr = Xr;
   for i=1:M
      Xr(i) = XX(i)*rd+XX(i+1)*(1-rd);
      Yr(i) = p+q*Xr(i)+r*Xr(i)^2 + 0.4*erfinv(2*rand(1) - 1);
   myrad = 0.05;
   for i=1:length(Xr)
      ball(Xr(i), Yr(i), myrad, red);
   axis equal;
   % least squares fitting
   Yr = Yr';
   Mat = [(0*Xr+1) Xr Xr.^2];
   pe = V(1); qe = V(2); re=V(3);
   plot(X, pe+qe*X+re*X.^2, 'b', 'linewidth', lw);
   grid on;
   set(gca, 'GridLineStyle', '-', 'xcolor', gray);
   set(gca, 'GridLineStyle', '-', 'ycolor', gray);
   set(gca, 'XTick', [-2 -1 0 1 2]);
   plot([-2 2], [3.5 3.5], 'linewidth', lw2, 'colour', gray);
   axis equal;
   axis([-2, 2, -1.7, 3.5]);
   saveas(gcf, 'Linear_least_squares2.eps', 'psc2'); % save as eps
   %plot2svg('Linear_least_squares.svg'); % save as svg
function ball(x, y, r, colour)
   H=fill(X, Y, colour);
   set(H, 'EdgeColor', 'none')
The following pages on Schools Wikipedia link to this image (list may be incomplete):

Learn more

Schools Wikipedia was launched to make learning available to everyone. SOS Children believes that a decent childhood is essential to a happy, healthy. Our community work brings families new opportunities through education, healthcare and all manner of support. Sponsoring a child is the coolest way to help.