NỘI SUY
NỘI SUY
NỘI SUY
x 0 1 2 4 5 6 8 9 10 11
F(x) -5 10 2 -6 -8 5 10 -12 11 10
Bảng 2: tìm hàm nội suy của f(x), tính gần đúng f(-3),f(-3)
x -6 -4 -2 0 2 4 6 8 10 12
F(x) -6 11 1 -10 -6 5 12 -15 11 15
Bảng 3: tìm hàm nội suy của f(x), tính gần đúng f(1.5),f(2,5)
x 0 3 6 9 12 15 18 21 24 27
F(x) 10 -10 12 -6 -9 6 16 -10 1 15
= x(x-1)(x-2)(x-4)(x-5)(x-6)(x-8)(x-9)(x-10)(x-11) *
f(3) = 3(3-1)(3-2)(3-4)(3-5)(3-6)(3-8)(3-9)(3-10)(3-11) * [(53^2 - 19283 + 945350)/(9453503(3-
1)(3-2)(3-4)(3-5)(3-6)(3-8)(3-9)(3-10)(3-11))]
= 321*(-1)(-2)(-3)(-5)(-6)(-7)(-8) * [(59 - 19283 + 945350)/(945350321(-1)(-2)(-3)(-5)(-6)(-7)(-
8))]
= -1512 * [(59 - 19283 + 945350)/(945350321(-1)(-2)(-3)(-5)(-6)(-7)(-8))]
= -1512 * [(45 - 5784 + 945350)/(945350321(-1)(-2)(-3)(-5)(-6)(-7)(-8))]
= -1512 * [939611/945350321(-1)(-2)(-3)(-5)(-6)(-7)(-8)]
= 0.49090909
Bảng 2:
W(x)=(x+6)(x+4)(x+2)(x)(x−2)(x−4)(x−6)(x−8)(x−10)(x−12)
𝑊′(−6)=(−6+4)(−6+2)(−6+0)(−6−2)(−6−4)(−6−6)(−6−8)(−6−10)(−6−12)=−10321920
𝑊′(−4)=(−4+6)(−4+2)(−4+0)(−4−2)(−4−4)(−4−6)(−4−8)(−4−10)(−4−12)=−7741440
𝑊′(−2)=(−2+6)(−2+4)(−2+0)(−2−2)(−2−4)(−2−6)(−2−8)(−2−10)(−2−12)=7741440
𝑊′(0)=(0+6)(0+4)(0+2)(0−2)(0−4)(0−6)(0−8)(0−10)(0−12)=−1900800
𝑊′(2)=(2+6)(2+4)(2+2)(2−0)(2−4)(2−6)(2−8)(2−10)(2−12)=−7741440
𝑊′(4)=(4+6)(4+4)(4+2)(4−0)(4−2)(4−4)(4−6)(4−8)(4−10)=7741440
𝑊′(6)=(6+6)(6+4)(6+2)(6−0)(6−2)(6−4)(6−6)(6−8)(6−10)=−10321920
𝑊′(8)=(8+6)(8+4)(8+2)(8−0)(8−2)(8−4)(8−6)(8−8)(8−10)=7741440
𝑊′(10)=(10+6)(10+4)(10+2)(10−0)(10−2)(10−4)(10−6)(10−8)(10−10)=−10321920
𝑊′(12)=(12+6)(12+4)(12+2)(12−0)(12−2)(12−4)(12−6)(12−8)(12−10)=7741440
L9(x) = W(x)=(x+6)(x+4)(x+2)(x)(x−2)(x−4)(x−6)(x−8)(x−10)(x−12)
−6 11 1 −6 5
( + + + + +
( x +6)(−10321920) ( x +4 )(−7741440) ( x ∓ 2 ) 7741440 ( x−2) 7741440 ( x−4 ) 7741440
+12 −15 11 12
+ + +
( x−6 ) (−10321920) ( x−8) 7741440 ( x−10 ) (−10321920) ( x−12)7741440
F(-3) = 11.24
F(-3.5) = 13.40
Phương pháp Largrange cách đều:
Bảng 2:
x+6
Đặt t = => x = 2t-6.
2
2 2 2 2 2 2 2 2 2
L9(-3) = 11.24
L9(-3.5 = 13.40
Bảng 3:
x
Đặt t = => x= 3t
3
L9(2t) = t(t-1)(t-2)(t-3)(t-4)(t-5)(t-6)(t-7)(t-8)(t-9)(
10∗9C 0 −10∗9 C 1 12∗9 C 2 −6∗9 C 3 −9∗9 C 4 6∗9C 6 16∗9 C 6 −10∗9 C 7 1∗9C 8 15∗9 C
− + − + − + − + −
t−0 t−1 t−2 t−3 t−4 t−5 t−6 t−7 t−8 t−9
L9(x) =
F(1.5) = -42.359947
Nội suy Anken:
Bảng 1: f(3.5)
3.50 -1.00 -2.00 -4.00 -5.00 -6.00 -8.00 -9.00 -10.00 -11.00 -6652800.00
1.00 2.50 -1.00 -3.00 -4.00 -5.00 -7.00 -8.00 -9.00 -10.00 756000.00
2.00 1.00 1.50 -2.00 -3.00 -4.00 -6.00 -7.00 -8.00 -9.00 -217728.00
4.00 3.00 2.00 -0.50 -1.00 -2.00 -4.00 -5.00 -6.00 -7.00 -20160.00
5.00 4.00 3.00 1.00 -1.50 -1.00 -3.00 -4.00 -5.00 -6.00 32400.00
6.00 5.00 4.00 2.00 1.00 -2.50 -2.00 -3.00 -4.00 -5.00 -72000.00
8.00 7.00 6.00 4.00 3.00 2.00 -4.50 -1.00 -2.00 -3.00 217728.00
9.00 8.00 7.00 5.00 4.00 3.00 1.00 -5.50 -1.00 -2.00 -332640.00
10.00 9.00 8.00 6.00 5.00 4.00 2.00 1.00 -6.50 -1.00 1123200.00
11.00 10.00 9.00 7.00 6.00 5.00 3.00 2.00 1.00 -7.50 -9355500.00
f(3.500000) = (0.000001 + 0.000013 + -0.000009 + 0.000298 + -0.000247 + -0.000069 +
0.000046 + 0.000036 + 0.000010 + -0.000001 ) * -29692.750000 = -2.279892
Bảng 3:
1.50 -3.00 -6.00 -9.00 -12.00 -15.00 -18.00 -21.00 -24.00 -27.00 -10713850880.00
3.00 -1.50 -3.00 -6.00 -9.00 -12.00 -15.00 -18.00 -21.00 -24.00 -1190427904.00
6.00 3.00 -4.50 -3.00 -6.00 -9.00 -12.00 -15.00 -18.00 -21.00 892820864.00
9.00 6.00 3.00 -7.50 -3.00 -6.00 -9.00 -12.00 -15.00 -18.00 -637729216.00
12.00 9.00 6.00 3.00 -10.50 -3.00 -6.00 -9.00 -12.00 -15.00 595213952.00
15.00 12.00 9.00 6.00 3.00 -13.50 -3.00 -6.00 -9.00 -12.00 -765275008.00
18.00 15.00 12.00 9.00 6.00 3.00 -16.50 -3.00 -6.00 -9.00 1403004288.00
21.00 18.00 15.00 12.00 9.00 6.00 3.00 -19.50 -3.00 -6.00 -3868890624.00
24.00 21.00 18.00 15.00 12.00 9.00 6.00 3.00 -22.50 -3.00 17856417792.00
27.00 24.00 21.00 18.00 15.00 12.00 9.00 6.00 3.00 -25.50 -182135472128.00
#include <stdio.h>
#include <math.h>
void PrintTable() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%.2f ", result[i][j]);
}
printf("\n");
}
printf("\n");
}
void PrintCol() {
for (int i = 0; i < n; i++) {
printf("%.2f\n", temp[i]);
}
printf("\n");
}
void FinalCol() {
float multi = 1.0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
multi *= result[i][j];
}
temp[i] = multi;
multi = 1.0;
}
}
float FindW() {
float multi = 1.0;
for (int i = 0; i < n; i++) {
multi *= result[i][i];
}
return multi;
}
void NoisuyAyken() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (j == i) {
result[i][j] = c - table[i];
} else {
result[i][j] = table[i] - table[j];
}
}
}
PrintTable();
FinalCol();
PrintCol();
float W = FindW();
float sum = 0;
printf("f(%f) = (", c);
for (int i = 0; i < n; i++) {
sum += value[i] / temp[i];
printf("%f ", value[i] / temp[i]);
if (i < n - 1) {
printf("+ ");
}
}
printf(") * %f = %f", W, sum * W);
}
int main() {
printf("nhap n : ");
scanf("%d", &n);
printf("nhap c: ");
scanf("%f", &c);
printf("nhap x: ");
Input(table);
printf("nhap f(x): ");
Input(value);
NoisuyAyken();
return 0;
}
Nội suy Newton:
Bảng 2:
Bảng sai phân:
xi f(xi) ∆2f(xi) ∆3f(xi) ∆4f(xi) ∆2f(xi) ∆2f(xi) ∆2f(xi) ∆2f(xi) ∆2f(xi) ∆2f(xi)
-6 -6
-4 11 17
-2 1 -10 -27
0 -10 -11 -1 26
2 -6 4 15 16 -10
4 5 1 7 -8 -24 -14
6 12 7 -4 -11 -3 21 35
8 -15 -27 -34 -30 -19 -16 -37 -72
10 11 26 53 87 117 136 152 189 261
12 15 4 22 75 -162 -279 -415 -567 -756 -1017
void IN() {
int k = 0;
for( int i = 0 ; i < n; i++ ) {
for( int j = 0; j < n; j++ ) {
printf("%d\t ", (int)result[i][j] );
}
printf("\n");
}
}
void Newton() {
int cnt = 0;
int k = 0;
do {
for( int i = 0; i < n; i++ ) {
if ( cnt == 0 ) {
result[i][k] = value[i];
} else if ( i < cnt ) {
result[i][k] = 0;
} else {
result[i][k] = result[i][k-1] - result[i-1][k-1];
}
}
cnt++;
k++;
} while( cnt < n );
}
int main() {
printf("nhap n : ");
scanf("%d", &n );
printf("nhap cac gia tri cua x: ");
Input( table );
printf("nhap gia tri cua f(x): ");
Input( value );
Newton();
IN();
}