Math ClubMath Club
v1 · padrão canônico

Mínimos Quadrados e Regressão

Equações normais, fatoração QR, mínimos quadrados ponderados, regularização de Tikhonov (ridge), regressão polinomial e aplicações em ajuste de curvas.

Used in: engenharia

Choose your door

Real scenarios with market data and step-by-step calculations

Aplicações de Mínimos Quadrados em Engenharia

Ajuste de Curva e Calibração de Sensores

Problema: calibrar um termopar medindo pares (Ti,Vi)(T_i, V_i) (temperatura, tensão). Modelo quadrático: V=a0+a1T+a2T2V = a_0 + a_1 T + a_2 T^2.

Configuração:

A=(1T1T121TmTm2),b=(V1Vm)A = \begin{pmatrix} 1 & T_1 & T_1^2 \\ \vdots & \vdots & \vdots \\ 1 & T_m & T_m^2 \end{pmatrix}, \quad b = \begin{pmatrix} V_1 \\ \vdots \\ V_m \end{pmatrix}

Código Python:

import numpy as np

# Dados de calibração
T = np.array([0, 25, 50, 75, 100, 125, 150])
V = np.array([0.0, 1.02, 2.05, 3.10, 4.13, 5.17, 6.18])

# Montar matriz de Vandermonde grau 2
A = np.column_stack([np.ones_like(T), T, T**2])

# Resolver via equações normais (ou np.linalg.lstsq)
c, residuals, rank, sv = np.linalg.lstsq(A, V, rcond=None)
print(f"Coeficientes: a0={c[0]:.4f}, a1={c[1]:.4f}, a2={c[2]:.6f}")

Ridge Regression — Controle de Multicolinearidade

from numpy.linalg import solve, norm

def ridge_regression(A, b, lam):
    n = A.shape[1]
    ATA = A.T @ A
    ATb = A.T @ b
    return solve(ATA + lam * np.eye(n), ATb)

# Comparar condicionamento
lambdas = [0, 0.01, 0.1, 1.0]
for lam in lambdas:
    M = A.T @ A + lam * np.eye(3)
    print(f"λ={lam:.2f}: cond(A^TA+λI) = {np.linalg.cond(M):.1f}")

Sistema de Controle — Identificação de Parâmetros

Identificar parâmetros a,b,ca, b, c do sistema y[k]=ay[k1]+by[k2]+cu[k1]y[k] = a\, y[k-1] + b\, y[k-2] + c\, u[k-1] via mínimos quadrados: montar o regresor ϕ[k]=(y[k1],y[k2],u[k1])T\phi[k] = (y[k-1], y[k-2], u[k-1])^T e empilhar observações.

Referências: Strang (2016) §4.3; Kay (1993) Cap. 8 (estimação de parâmetros).

To continue

Referências Bibliográficas

  • Strang, G. Introduction to Linear Algebra, 5ª ed. Wellesley-Cambridge Press, 2016. §§4.2–4.4 (projeções e mínimos quadrados), §4.5 (pseudo-inversa).
  • Strang, G. Linear Algebra and Its Applications, 4ª ed. Thomson Brooks/Cole, 2006. §4.3–4.4 (fatoração QR).
  • Lay, D.C.; Lay, S.R.; McDonald, J.J. Linear Algebra and Its Applications, 5ª ed. Pearson, 2016. §§6.5–6.6 (mínimos quadrados e equações normais).
  • Golub, G.H.; Van Loan, C.F. Matrix Computations, 4ª ed. Johns Hopkins Univ. Press, 2013. §5.3 (QR), §12.1 (regularização), §12.3 (TLS).
  • Kay, S.M. Fundamentals of Statistical Signal Processing, Volume I: Estimation Theory. Prentice Hall, 1993. §§8–12 (estimação de mínimos quadrados e RLS).
  • Hansen, P.C. Rank-Deficient and Discrete Ill-Posed Problems. SIAM, 1998. §§2–3 (SVD e regularização de Tikhonov).
  • Tikhonov, A.N.; Arsenin, V.Y. Solutions of Ill-Posed Problems. Wiley, 1977. (referência clássica para regularização).
  • Horn, R.A.; Johnson, C.R. Matrix Analysis, 2ª ed. Cambridge Univ. Press, 2013. §§2–3 (normas matriciais e pseudoinversa).

Updated on 2026-05-28 · Author(s): Clube da Matemática

Found an error? Open an issue on GitHub or submit a PR — open source forever.