File:Regression quadratique lineaire donnees gander.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file(SVG file, nominally 452 × 369 pixels, file size: 27 KB)

Captions

Captions

Add a one-line explanation of what this file represents

Summary[edit]

Description
English: Fitting the data with a quadratic function (conic section). Data points from Gander, W., Golub, Gene, H. and Strebel, R., Least-Squares Fitting of Circles and Ellipses, BIT 34 (1994), 558-578. The result is an ellipse.
Français : Régression par une fonction quadratique (conique). Nuage de points de Gander, W., Golub, Gene, H. and Strebel, R., Least-Squares Fitting of Circles and Ellipses, BIT 34 (1994), 558-578. Le résultat est une ellipse.
Date
Source Own work
Author Cdang

Parameters of the ellipse:

  • cartesian equation: x2 + 0.815xy + 0.719y2 – 14.0x – 10.1 = 0;
  • geometrical parameters:
    • center C(5.38, 4.00),
    • semi-axes: a = 2.80, b = 5.10,
    • tilt: φ = 35.5°.

Scilab source

// **********
// Initialisation
// **********

clear;

// **********
// Données
// **********

X0 = [1, 2, 5, 7, 9, 6, 3, 8];
Y0 = [7, 6, 8, 7, 5, 7, 2, 4];

// **********
// Fonctions
// **********

function [a] = regression_quadratique(X, Y) 
    // méthode de la distance algébrique
    // X, Y : points expérimentaux, matrices colonnes réelles
    // a : coefficients de la formule quadratique (matrice colonne réelle)
    YY = (X.*X); 
    XX = [(X.*Y) ; (Y.*Y) ; X ; Y]; 
    [aa, b] = reglin(XX, YY);
    a = [-aa, -b];
endfunction

function [phi]=trouve_rotation(A)
    // A : coefficients de la formule quadratique (matrice colonne réelle)
    // phi : angle que fait un axe de l'ellipse avec x (radians)
    delta = 1 - 1/(1 + (A(3) - A(1))^2/A(2)^2);
    absphi = acos(sqrt((1 + sqrt(delta))/2));
    cap = cos(absphi); sap = sin(absphi);
    signephi = sign(A(2)*(cap*cap - sap*sap)/(A(1) - A(3)));
    phi = signephi*absphi;
endfunction

function [x,y]=trouve_centre(A)
    // A : coefficients de la formule quadratique (matrice colonne réelle)
    // x, y : coordonées du centre de l'ellipse (réels)
    delta = A(2)*A(2) - 4*A(1)*A(3);
    x = (2*A(3)*A(4) - A(2)*A(5))/delta;
    y = (2*A(1)*A(5) - A(2)*A(4))/delta;
endfunction

function [rx, ry]=trouve_rayons(a, phi, xc, yc)
    // a : coefficients de la formule quadratique (matrice colonne réelle)
    // phi : angle que fait un axe de l'ellipse avec x
    // xc, yc : coordonnées du centre de l'ellipse
    // rx, ry : rayons (grand et petit demi-grands axes) de l'ellipse
    A = [a(1), a(2)/2 ; a(2)/2, a(3)];
    Q = rotate([1, 0 ; 0, 1], phi); // matrice de rotation
    t = [xc ; yc]; // matrice de translation
    Abar = Q'*A*Q;
    b = [a(4) ; a(5)];
    bbar = (2*t'*A + b')*Q;
    c = a(6);
    cbar = t'*A*t + b'*t + c;
    rx = sqrt(abs(cbar/Abar(1,1)));
    ry = sqrt(abs(cbar/Abar(2,2)));
endfunction

function [d]=conique(a, x, y)
    d = a(1)*x'*x + a(2)*x'*y + a(3)*y'*y + a(4)*x + a(5)*y + a(6);
endfunction

function [] = trace_conique(a)
    epsilon = 1.5e-1;
    Xbase = 0:0.1:10;
    Ybase = 1:0.1:9;
    i = 1;
    for x = Xbase
        for y = Ybase
            if abs(conique(a, x, y)) <= epsilon then
                X(i) = x;
                Y(i) = y;
                i = i + 1;
            end
        end
    end
    Xmoy = mean(X); Ymoy = mean(Y); // détermination d'un point intérieur
    theta = atan(Y-Ymoy, X-Xmoy); // angle des vecteurs
    posMat = gsort([theta, X, Y], "lr"); // classement dans le sens trigo
    [m, k] = max(abs(diff(posMat(:, 1)))); // saut de point
    X = [posMat(k+1:$, 2) ; posMat(1:k, 2)]; // décalage circulaire
    Y = [posMat(k+1:$, 3) ; posMat(1:k, 3)];
    plot2d(X, Y, style = 5);
endfunction

// **********
// Programme principal
// **********

// lecture des données

Xdef = X0;
Ydef = Y0;

// Régression
Aopt = regression_quadratique(Xdef, Ydef);
aopt = [1, Aopt];

// affichage des paramètres
disp(aopt)

phi = trouve_rotation(aopt);
phideg = phi*180/%pi;
[xc, yc] = trouve_centre(aopt);
[a, b] = trouve_rayons(aopt, phi, xc, yc);
disp("phi = "+string(phi)+" rad = "+string(phideg)+"°.");
disp("C("+string(xc)+" ; "+string(yc)+").");
disp("a = "+string(a)+" ; b = "+string(b)+".");

// tracé
clf;

plot(Xdef, Ydef, "b+")
replot([0, 10 ; 1, 9]);
plot(xc, yc, "r+")
trace_conique(aopt)

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following licenses:
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported, 2.5 Generic, 2.0 Generic and 1.0 Generic license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
You may select the license of your choice.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current12:29, 24 May 2018Thumbnail for version as of 12:29, 24 May 2018452 × 369 (27 KB)Cdang (talk | contribs)continuous line
10:10, 20 December 2012Thumbnail for version as of 10:10, 20 December 2012452 × 364 (39 KB)Cdang (talk | contribs){{Information |Description ={{en|1=Fitting the data with a quadratic function (conic section). Data points from Gander, W., Golub, Gene, H. and Strebel, R., ''Least-Squares Fitting of Circles and Ellipses'', BIT 34 (1994), 558-578. The result is an...

There are no pages that use this file.

File usage on other wikis

The following other wikis use this file:

Metadata