Numer ćw.: | Nazwa wydziału: | Ocena: |
---|---|---|
2 | Wydział Inżynierii Elektrycznej i Komputerowej | |
Grupa stud. / grupa lab. | ||
MiDUE | Nazwa przedmiotu: | |
Data wykonania ćw.: | Metody numeryczne | |
Temat ćw.: | Podpis: | |
Data oddania sprawozdania: | Wielomiany | |
Skład zespołu | ||
Łukasz Kąkol Michał Kurek |
Sprawozdanie zostało wykonane na ocenę 3.0 a więc wielomian Lagrange z funkcjami kardynalnymi.
----------------------------------------------------------------------------------------------
clc
% zadane punkty pomiarowe
x0=1;
x1=2;
x2=3;
x3=4;
x4=5;
x5=6;
x6=7;
x7=8;
X=[x0;x1;x2;x3;x4;x5;x6;x7];
y0=3;
y1=5;
y2=2;
y3=4;
y4=3;
y5=6;
y6=3;
y7=8;
x=[0.7:0.01:8];
Y=[y0;y1;y2;y3;y4;y5;y6;y7]
% macierz wielomianu
A=[1 x0 x0^2 x0^3 x0^4 x0^5 x0^6 x0^7
1 x1 x1^2 x1^3 x1^4 x1^5 x1^6 x1^7
1 x2 x2^2 x2^3 x2^4 x2^5 x2^6 x2^7
1 x3 x3^2 x3^3 x3^4 x3^5 x3^6 x3^7
1 x4 x4^2 x4^3 x4^4 x4^5 x4^6 x4^7
1 x5 x5^2 x5^3 x5^4 x5^5 x5^6 x5^7
1 x6 x6^2 x6^3 x6^4 x6^5 x6^6 x6^7
1 x7 x7^2 x7^3 x7^4 x7^5 x7^6 x7^7]
%obliczamy szukane współczynniki a0...a7
C=inv(A);
D=C*Y; % wektor współczynników a
a0=D(1)
a1=D(2)
a2=D(3)
a3=D(4)
a4=D(5)
a5=D(6)
a6=D(7)
a7=D(8)
% wielomian Lagrange: L(x)=a0L0(x)+a1L1(x)...+an-1Ln-1(x)
L=a0+(a1*x)+(a2*x.^2)+(a3*x.^3)+(a4*x.^4)+(a5*x.^5)+(a6*x.^6)+(a7*x.^7);
%wykres wielomianu Lagrange dla danych węzłów
figure(1)
plot(x,L)
grid on,title('Wielomian Lagrange L(x)'),xlabel('X^T,x'),ylabel('Y^T')
hold on
plot(X,Y,'o r'), % zaznaczenie na wykresie punktów pomiarowych
%Funckje kardynalne
C0=((x-x1).*(x-x2).*(x-x3).*(x-x4).*(x-x5).*(x-x6).*(x-x7))/((x0-x1).*(x0-x2).*(x0-x3).*(x0-x4).*(x0-x5).*(x0-x6).*(x0-x7));
C1=((x-x0).*(x-x2).*(x-x3).*(x-x4).*(x-x5).*(x-x6).*(x-x7))/((x1-x0).*(x1-x2).*(x1-x3).*(x1-x4).*(x1-x5).*(x1-x6).*(x1-x7));
C2=((x-x0).*(x-x1).*(x-x3).*(x-x4).*(x-x5).*(x-x6).*(x-x7))/((x2-x0).*(x2-x1).*(x2-x3).*(x2-x4).*(x2-x5).*(x2-x6).*(x2-x7));
C3=((x-x0).*(x-x1).*(x-x2).*(x-x4).*(x-x5).*(x-x6).*(x-x7))/((x3-x0).*(x3-x1).*(x3-x2).*(x3-x4).*(x3-x5).*(x3-x6).*(x3-x7));
C4=((x-x0).*(x-x1).*(x-x2).*(x-x3).*(x-x5).*(x-x6).*(x-x7))/((x4-x0).*(x4-x1).*(x4-x2).*(x4-x3).*(x4-x5).*(x4-x6).*(x4-x7));
C5=((x-x0).*(x-x1).*(x-x2).*(x-x3).*(x-x4).*(x-x6).*(x-x7))/((x5-x0).*(x5-x1).*(x5-x2).*(x5-x3).*(x5-x4).*(x5-x6).*(x5-x7));
C6=((x-x0).*(x-x1).*(x-x2).*(x-x3).*(x-x4).*(x-x5).*(x-x7))/((x6-x0).*(x6-x1).*(x6-x2).*(x6-x3).*(x6-x4).*(x6-x5).*(x6-x7));
C7=((x-x0).*(x-x1).*(x-x2).*(x-x3).*(x-x4).*(x-x5).*(x-x6))/((x7-x0).*(x7-x1).*(x7-x2).*(x7-x3).*(x7-x4).*(x7-x5).*(x7-x6));
L00=C0*y0;
L11=C1*y1;
L22=C2*y2;
L33=C3*y3;
L44=C4*y4;
L55=C5*y5;
L66=C6*y6;
L77=C7*y7;
Lc=L00+L11+L22+L33+L44+L55+L66+L77;
%Wykresy funkcji składowych
figure(2)
subplot(2,2,1)
plot(x,L00),grid on
title('L00(x)'),xlabel('X^T,x'),ylabel('Y^T')
hold on
plot(X,Y,'o r')
subplot(2,2,2)
plot(x,L11), grid on,title('L11(x)'),xlabel('X^T,x'),ylabel('Y^T')
hold on
plot(X,Y,'o r')
subplot(2,2,3)
plot(x,L22),grid on,title('L22(x)'),xlabel('X^T,x'),ylabel('Y^T')
hold on
plot(X,Y,'o r')
subplot(2,2,4)
plot(x,L33),grid on, title('L33(x)'),xlabel('X^T,x'),ylabel('Y^T')
hold on
plot(X,Y,'o r')
figure(3)
subplot(2,2,1)
plot(x,L44),grid on, title('L44(x)'),xlabel('X^T,x'),ylabel('Y^T')
hold on
plot(X,Y,'o r')
subplot(2,2,2)
plot(x,L55),grid on, title('L55(x)'),xlabel('X^T,x'),ylabel('Y^T')
hold on
plot(X,Y,'o r')
subplot(2,2,3)
plot(x,L66),grid on, title('L66(x)'),xlabel('X^T,x'),ylabel('Y^T')
hold on
plot(X,Y,'o r')
subplot(2,2,4)
plot(x,L77),grid on, title('L77(x)'),xlabel('X^T,x'),ylabel('Y^T')
hold on
plot(X,Y,'o r')
figure(4)
plot(x,Lc),grid on, title('Lc(x)'),xlabel('X^T,x'),ylabel('Y^T')
hold on
plot(X,Y,'o r')