Use o botão abaixo para reportar erros ou dar sugestões.

Cálculo Numérico - Versão Scilab

6.5 Interpolação linear segmentada


Considere o conjunto xi,yi j=1n de n pontos. Assumiremos que xi+1 > xi, ou seja, as abscissas são distintas e estão em ordem crescente. A função linear que interpola os pontos xi e xi+1 no intervalo i é dada por

Pi(x) = yi (xi+1 − x) (xi+1 − xi) + yi+1 (x − xi) (xi+1 − xi) (6.61)

O resultado da interpolação linear segmentada é a seguinte função contínua definida por partes no intervalo [x1,xn]:

f(x) = Pi(x),x ∈ [xi,xi+1] (6.62)

Exemplo 6.5.1. Construa uma função linear por partes que interpola os pontos (0,0), (1,4), (2,3), (3,0), (4,2), (5,0).

A função procurada pode ser construída da seguinte forma:

f(x) = 0x−1 0−1 + 1x−0 1−0 , 0 ≤ x < 1 4x−2 1−2 + 3x−1 2−1 , 1 ≤ x < 2 3x−3 2−3 + 0x−2 3−2 , 2 ≤ x < 3 0x−4 3−4 + 2x−3 4−3 , 3 ≤ x < 4 2x−5 4−5 + 0x−4 5−4 , 4 ≤ x ≤ 5 (6.63)

Simplificando, obtemos:

f(x) = x, 0 ≤ x < 1 − x + 5, 1 ≤ x < 2 − 3x + 9, 2 ≤ x < 3 2x − 6, 3 ≤ x < 4 − 2x + 10, 4 ≤ x ≤ 5 (6.64)

A Figura 6.3 é um esboço da função f(x) obtida.

Ela foi gerada no Scilab usando os comandos:

//pontos fornecidos  
xi = [0;1;2;3;4;5]  
yi = [0;4;3;0;2;0]  
//numero de pontos  
n = 6  
//funcao interpoladora  
function [y] = f(x)  
  for i=1:n-2  
    if ((x>=xi(i)) & (x<xi(i+1))) then  
      y = yi(i)*(x-xi(i+1))/(xi(i) - xi(i+1)) ...  
          + yi(i+1)*(x-xi(i))/(xi(i+1) - xi(i));  
    end  
  end  
 
  if ((x>=xi(n-1)) & (x<=xi(n))) then  
    y = yi(n-1)*(x-xi(n))/(xi(n-1) - xi(n)) ...  
        + yi(n)*(x-xi(n-1))/(xi(n) - xi(n-1));  
  end  
endfunction  
//graficando  
xx = linspace(xi(1),xi(n),500)’;  
clear yy  
for i=1:max(size(xx))  
  yy(i) = f(xx(i))  
end  
plot(xi,yi,’r.’,xx,yy,’b-’)


PIC

Figura 6.3: Interpolação linear segmentada.


Creative Commons License Este texto é disponibilizado nos termos da licença Creative Commons Atribuição-CompartilhaIgual 3.0 Não Adaptada (CC-BY-SA 3.0). Página gerada em 19/8/2020 às 17:36:32.

Informe erros ou edite você mesmo!