You are on page 1of 12

Subiect IP_01

Explicati metoda de interpolare numerica


folosind polinoame Lagrange
Explain the interpolation method based on
Larange Polynomial

suppose a set of data points:
{(

) (

) (

)}
Lagrange interpolation involves simply fitting an

degree polynomial function exactly through this


data:

()


for each of the data points:
{(

) (

) (

)}
the polynomial function take the value


in matrix form the system becomes:
[

[]


consider the

polynomial:

()

)(

) (

)(

) (

()


Note: choosing

in order to normalize

) (

)(

) (

)
((


results the relationship:

{



A linear combination of the polynomials:

() (

()


provides the

polynomial which EXACTLY passes through ALL data points by construction.



Subiect IP_02
Explicati metoda de interpolare numerica
folosind polinoame Newton
Explain the interpolation method based on
Newton Polynomial

the

- degree Lagrange polynomial needs restarting the whole calculation when data points are
added,
the

degree Newton polynomial can be recursively obtained from the ( )

polynomial:
{(

) (

) (

)}

()

)(

) (

)

{(

) (

) (

)}

()

)(

) (

)
Newton polynomial recurrence relation:

()

()

) (

)
with

()


for the first degree Newton polynomial, determine

and

so that:

()

()


for the second degree Newton polynomial, will have the same

and

so that:

()

()

)(

)(

)
the second degree Newton polynomial still matches first two data points and has to match the third
point:

)(


for only one more coefficient calculated :

)
(

)(

)
(

)(


define constant:


generalizing previous results :


the divided difference table is:





Subiect IP_03
Explicati metoda de interpolare numerica
folosind polinoame spline
Explain the interpolation method based on Spline
Polynomial
Spline polynomial order:
linear splines are line segments connecting each pair of data points. Linear splines are
independent of each other from interval to interval. The slopes (first order derivatives) and
curvature (second order derivatives) are discontinuous at every data point.
quadratic splines are second-order approximating polynomials. The slopes can be forced to
be continuous at each data point, but the curvatures are still discontinuous.
cubic splines yields a third-order polynomial connecting each pair of data points. The slopes
and curvatures can be forced to be continuous at each data point. Cubic splines have proven
a good compromise between accuracy and complexity.
total number of grid points:


total number of intervals:

total number of interior grid points:


cubic spline equation

() on interval:

()


( ) conditions of functions continuity - the spline functions value must be the same in
the two splines on either side of all ( ) points,


( ) conditions of first order derivatives continuity the first derivative of the two splines
on either side of

must be equal at all ( ) interior points ,

)
( ) conditions of second order derivatives continuity the first derivative of the two
splines on either side of

must be equal at all ( ) interior points ,

)
conditions for the first and last spline functions must pass through first

and last point


conditions for the first and last grid point on the second order derivative of the spline
functions must be defined,

and

()

()

()

()

)
(

)
(

] (

) [

] (

()

[
(

)]

[
(

)]

()

[
(

[
(



unknown second order derivative:

maybe found imposing condition:




the equation system:


is a equations with unknowns:

...,


the two remaining equation are found by prescribing:
parabolic run-out conditions:


free run-out conditions natural splines:


periodic end - conditions:



Subiect NI_11
Scrieti si testati un program Matlab pentru
calculul numeric al functiilor de interpolare
folosind polinoame Lagrange
Implement and test a Matlab program for
numerical interpolation method based on
Lagrange Polynomials
programul principal de test:
% initializeaza programul
clc
clear all
format long e
%
% -------------------------------------------------------------
% functia test este
% f(x)=sin(x)/x
% defineste limitele de test pentru interpolarea functiei f(x)
lim_inf=-12;
lim_sup=12;
%
% pregatire date problema interpolare
% -------------------------------------------------------------
% pasul de generare a punctelor pentru graficul continuu al functiei
pas_x=0.1;
% determina puncte din graficul functiei test
[x0,y0]=init_data(pas_x,lim_inf,lim_sup);
% reprezinta grafic continuu functia initiala
plot(x0,y0);
hold on;
% -------------------------------------------------------------
% genereaza seria de puncte de testare interpolare
% seria de puncte existente
% numarul de puncte de test pe care se construieste
% polinomul Lagrange
np=12;
% pasul de generare pentru punctele de test
pas_x=(lim_sup-lim_inf)/(np-1);
% determina punctele de test
[x, y]=init_data(pas_x,lim_inf,lim_sup);
% reprezinta grafic punctele de test
plot(x,y,'ko');
hold on;
%
%seria de puncte in care se testeaza interpolarea
np=6;
% pasul punctelor de test
pas_x=(lim_sup-lim_inf)/(np-1);
% vectorul punctelor de test
xp=[lim_inf:pas_x:lim_sup];
% testeaza polinomul de interpolare in punctele de test
for i=1:np
% calculeaza valoarea aproximativa interpolata
yp(i)=lagrange(xp(i),x,y);
% reprezinta grafic punctul interpolat
plot(xp(i),yp(i),'x');
end

functia de generare a punctelor de test
function [x_vect, y_vect] = init_data(step,lim_inf,lim_sup)
% genereaza vectorul absciselor punctelor de test
x_vect=lim_inf:step:lim_sup;
% calculeaza valoarea functiei in punctele de test
y_vect=sin(x_vect+eps)./(x_vect+eps);
end

functia de calcul a polinomului Lagrange
function p = lagrange(x,x_vect,y_vect)
% determina dimensiunea vectorului punctelor de interpolare
n=size(x_vect);
% initializeaza valoarea polinomului de interpolare
p=0;
% calculeaza valoarea polinomului de interpolare
for i=1:n
% initializeaza valoarea polinomului Lagrange
L=1;
% calculeaza valoare produsului
for j=1:n
if (j ~=i)
L=L*(x-x_vect(j))/(x_vect(i)-x_vect(j));
end
end
% actualizeaza valoarea polinomului Lagrange
p=p+y_vect(i)*L;
end
end


Subiect IP_12
Scrieti si testati un program Matlab pentru
calculul numeric al functiilor de interpolare
folosind polinoame Newton
Implement and test a Matlab program for
numerical interpolation method based on
Newton Polynomials
programul principal de test:
clear all
clc
clf
x=[-2 -1 1 2 4];
y=[-6 0 0 6 60];
n=newton(x,y);
xx=[-2:0.02:2];
yy=polyval(n,xx);
clf
plot(xx, yy, 'b-',x,y,'*');

functia de calcul a polinomului Newton
function [p] = newton(x,y)
% date de intrare in functie:
% x = [x0 x1 x2 ... xn]
% y = [y0 y1 y2 ... yn]
% date de iesire din functie:
% p = vectorul puterilor polinomului
% ----------------------------------------
% calculul variabilelor temporare
% n1 = dimensiunea vectorilor
% n0 = ordinul pinomului
n1=length(x);
n0=n1-1;
% initializare cu zero matrice DD
DD = zeros(n1,n1);
DD(1:n1,1)=y';
for i=2:n1
for j=1:n0+2-i
DD(j,i)=(DD(j+1,i-1)-DD(j,i-1))/(x(j+i-1)-x(j));
end
end
a=DD(1,:);
p=a(n1);
for i=n0:-1:1
p=[p a(i)]-[0 p*x(i)];
end
end



Subiect IP_13
Scrieti si testati un program Matlab pentru
calculul numeric al functiilor de interpolare
folosind polinoame Spline
Implement and test a Matlab program for
numerical interpolation method based on Spline
Polynomials
Programul principal de test:
% test_spline
clear;
clc;
clf;

global end_condition;
global x_data;
global y_data;
global g;
global delta;

% input data
[x_data,y_data]=input_spline;
plot(x_data,y_data,' ko');
axis([-13 11 -0.3 1.1]);
hold on;

x_lower=min(x_data);
x_upper=max(x_data);
xx=[x_lower:(x_upper-x_lower)/200:x_upper];

% set the end conditions to try
for end_condition=1:2
spline_setup;
for i=1:201
y_spline(i)=spline_interp(xx(i),x_data,y_data,g,delta);
end
plot(xx,y_spline);
end

functia de generarea a punctelor de interpolare
function [x_data,y_data] = input_spline
x_data=[-12:2:10];
y_data=sin(x_data+eps)./(x_data+eps);
end

programul de calcul a coeficientilor spline_setup
global end_condition;
global x_data;
global y_data;
global g;
global delta;

% compute the size of th eproblem
n=length(x_data);

% setup the delta_i=x_(i+1)-x_(i) for i=1...(n-1)
delta(1:n-1)=x_data(2:n)-x_data(1:n-1);

% setup and solve a tridiagonal system
for i=2:n-1
a(i)=delta(i-1)/6;
b(i)=(delta(i-1)+delta(i))/3;
c(i)=delta(i)/6;
g(i)=(y_data(i+1)-y_data(i))/delta(i)- ...
(y_data(i)-y_data(i-1))/delta(i-1);
end
if end_condition==1
% implement parabolic run-out
b(1)=1;
c(1)=-1;
g(1)=0;
b(n)=1;
a(n)=-1;
g(n)=0;
elseif end_condition==2
% implement free run-out
b(1)=1;
c(1)=0;
g(1)=0;
b(n)=1;
a(n)=0;
g(n)=0;
end

% solve the tridiagonal equation system
% forward step
for j=1:n-1
a(j+1)=-a(j+1)/b(j);
b(j+1)=b(j+1)+a(j+1)*c(j);
g(j+1)=g(j+1)+a(j+1)*g(j);
end
% back substitution
g(n)=g(n)/b(n);
for i=n-1:-1:1
g(i)=(g(i)-c(i)*g(i+1))/b(i);
end

functia de calcul a polinoamelor spline
function [f] = spline_interp(x,x_data,y_data,g,delta)
n=length(x_data);
% find that value of i such that x_data(i)<=x<=x_data(i+1)
for i=1:n-1
if x_data(i+1)>x
break
end
end

% compute the cubic spline approximation of the function
f=g(i)/6 *((x_data(i+1)-x)^3/delta(i)-delta(i)*(x_data(i+1)-x))+...
g(i+1)/6*((x- x_data(i))^3/delta(i)-delta(i)*(x-x_data(i)))+...
(y_data(i)*(x_data(i+1)-x)+y_data(i+1)*(x-x_data(i)))/delta(i);
end

You might also like