Anda di halaman 1dari 7

TrabajoEncargado

2. calcular el polinomio por el metodo de la Lagrange que interpola al conjunto de datos.


{(- 5, 1), (- 3, 2), (2, 10), (3, 2), (6, 0), (8, - 3)}

n=5
Clear[L]
x0 = - 5; x1 = - 3; x2 = 2; x3 = 3; x4 = 6; x5 = 8;
y0 = 1; y1 = 2; y2 = 10; y3 = 2; y4 = 0; y5 = - 3;
xint = - 3;
k-1 x - xi n x - xi
L[n_, k_, x_] :=  
i=0
xk - xi i=k+1
xk - xi
For[k = 0, k ≤ n, Print["L"n,k , "(", x, ")=" Expand[L[n, k, x]]];
k ++]
5

54 171 x 3 x2 67 x3 x4 x5
L5,0 (x)= - + - - + -
1001 4004 1001 16 016 1001 16 016
8 37 x 74 x2 29 x3 7 x4 x5
L5,1 (x)= - + + - +
33 165 1485 5940 2970 5940
18 33 x 107 x2 31 x3 3 x4 x5
L5,2 (x)= - - + + -
7 140 280 840 280 840
31 x 17 x2 37 x3 x4 x5
L5,3 (x)= - 2 + + - - +
60 45 720 90 720
10 17 x 125 x2 43 x3 5 x4 x5
L5,4 (x)= - - + + -
33 132 2376 2376 2376 2376
9 21 x 29 x2 37 x3 x4 x5
L5,5 (x)= - + + - - +
143 715 2860 8580 2860 8580

Programa de lagrange con el bucle for


2 111111111111111111111111111111111111111.nb

n=5
x0 = - 5; x1 = - 3; x2 = 2; x3 = 3; x4 = 6; x5 = 8;
y0 = 1; y1 = 2; y2 = 10; y3 = 2; y4 = 0; y5 = - 3;
(*inicio del programa*)
xint = - 3;
(*inicio del programa*)
fxint = 0;
Fori = 0, i ≤ n,
L = 1;
Forj = 0, j ≤ n,
xint - xj
Ifi ≠ j, L = L 
xi - xj

; j ++;
fxint = fxint + L * yi
; i ++
(*fin del programa*)
Round[fxint]
5

Programa lagrenge con el bucle while


111111111111111111111111111111111111111.nb 3

n=5
x0 = - 5; x1 = - 3; x2 = 2; x3 = 3; x4 = 6; x5 = 8;
y0 = 1; y1 = 2; y2 = 10; y3 = 2; y4 = 0; y5 = - 3;
xint = - 3;
(*inicio del programa*)
fxint = 0;
i = 0;
Whilei ≤ n, L = 1;
j = 0;
Whilej ≤ n,
xint - xj
Ifi ≠ j, L = L 
xi - xj

; j ++;
fxint = fxint + L * yi
; i ++
(*fin del programa*)
Round[fxint]
5

3. Calcular el polinomio por el método de Newton que interpola al conjunto de datos


{(- 5, 1), (- 3, 2), (2, 10), (3, 2), (6, 0), (8, - 3)}

n=5
Clear[L]
x0 = - 5; x1 = - 3; x2 = 2; x3 = 3; x4 = 6; x5 = 8;
Q0,0 = 1; Q1,0 = 2; Q2,0 = 10; Q3,0 = 2; Q4,0 = 0; Q5,0 = - 3;
xint = - 3;
Fori = 0, i ≤ n,

Forj = 1, j ≤ i,
Qi,j-1 - Qi-1,j-1
Qi,j = ; j ++; i ++;
xi - xi-j
Tableqi,j , Qi,j // N, {i, 0, n}, {j, 0, i} // TableForm
n i-1
p[x_] :=  Qi,i  x - xj  ;
i=0 j=0

p[x_] // Expand
Round[p[x] /. x → xint]
5
4 111111111111111111111111111111111111111.nb

q0,0
1.
q1,0 q1,1
2. 0.5
q2,0 q2,1 q2,2
10. 1.6 0.157143
q3,0 q3,1 q3,2 q3,3
2. - 8. - 1.6 - 0.219643
q4,0 q4,1 q4,2 q4,3 q4,4
0. - 0.666667 1.83333 0.381481 0.0546477
q5,0 q5,1 q5,2 q5,3 q5,4 q5,5
- 3. - 1.5 - 0.166667 - 0.333333 - 0.0649832 - 0.00920237

x_ 11 x_2 123 x_3 9089 x_4 19 897 x_5 x_0 11 x_ x_0 123 x_2 x_0
1+ + - + - - - + -
2 70 560 166 320 2 162 160 2 70 560
9089 x_3 x_0 19 897 x_4 x_0 11 x_ x_1 123 x_2 x_1 9089 x_3 x_1 19 897 x_4 x_1
+ - + - + +
166 320 2 162 160 70 560 166 320 2 162 160
11 x_0 x_1 123 9089 x_2 x_0 x_1 19 897 x_3 x_0 x_1 123 x_2 x_2
- x_ x_0 x_1 + - + -
70 560 166 320 2 162 160 560
9089 x_3 x_2 19 897 x_4 x_2 123 9089 x_2 x_0 x_2 19 897 x_3 x_0 x_2
+ - x_ x_0 x_2 + - -
166 320 2 162 160 560 166 320 2 162 160
123 9089 x_2 x_1 x_2 19 897 x_3 x_1 x_2 123 9089 x_ x_0 x_1 x_2
x_ x_1 x_2 + - + x_0 x_1 x_2 - +
560 166 320 2 162 160 560 166 320
19 897 x_2 x_0 x_1 x_2 9089 x_3 x_3 19 897 x_4 x_3 9089 x_2 x_0 x_3
- + + -
2 162 160 166 320 2 162 160 166 320
19 897 x_3 x_0 x_3 9089 x_2 x_1 x_3 19 897 x_3 x_1 x_3 9089 x_ x_0 x_1 x_3
+ - - +
2 162 160 166 320 2 162 160 166 320
19 897 x_2 x_0 x_1 x_3 9089 x_2 x_2 x_3 19 897 x_3 x_2 x_3 9089 x_ x_0 x_2 x_3
+ - - +
2 162 160 166 320 2 162 160 166 320
19 897 x_2 x_0 x_2 x_3 9089 x_ x_1 x_2 x_3 19 897 x_2 x_1 x_2 x_3 9089 x_0 x_1 x_2 x_3
- + + -
2 162 160 166 320 2 162 160 166 320
19 897 x_4 x_4 19 897 x_3 x_0 x_4
(19 897 x_ x_0 x_1 x_2 x_3 ) / 2 162 160 + - -
2 162 160 2 162 160
19 897 x_3 x_1 x_4 19 897 x_2 x_0 x_1 x_4 19 897 x_3 x_2 x_4 19 897 x_2 x_0 x_2 x_4
+ - + +
2 162 160 2 162 160 2 162 160 2 162 160
19 897 x_2 x_1 x_2 x_4 19 897 x_3 x_3 x_4
- (19 897 x_ x_0 x_1 x_2 x_4 ) / 2 162 160 - +
2 162 160 2 162 160
19 897 x_2 x_0 x_3 x_4 19 897 x_2 x_1 x_3 x_4
+ - (19 897 x_ x_0 x_1 x_3 x_4 ) / 2 162 160 +
2 162 160 2 162 160
19 897 x_2 x_2 x_3 x_4
- (19 897 x_ x_0 x_2 x_3 x_4 ) / 2 162 160 -
2 162 160
(19 897 x_ x_1 x_2 x_3 x_4 ) / 2 162 160 + (19 897 x_0 x_1 x_2 x_3 x_4 ) / 2 162 160

2
111111111111111111111111111111111111111.nb 5

Programa de Newton más sofisticado para


determinar polinomio interpolante con el Bucle For

puntos := {{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}};
xint = - 3;(*Valor a interpolar*)
n = Length[puntos] - 1;
For[i = 0, i ≤ n, i ++, xi = puntos[[i + 0, 1]]; yi = puntos[[i + 1, 2]]]
CLear[d];
dif = Array[d, {2 n + 2, n + 2}, - 1];
For[i = - 1, i ≤ 2 n, i ++,
For[j = - 1, j ≤ n, j ++, d[i, j] = " "]]
d[- 1, 1] = "xk "; d[- 1, 0] = "yk ";
For[i = 0, i ≤ n + 1, i ++, d[2 i, - 1] = xi ; d[2 i, 0] = yi ]
dif // MatrixForm;
For[j = 1, j ≤ n, j ++,
For[i = j, i ≤ 2 n - j, i = i + 2,
d[i, j] = (d[i + 1, j - 1] - d[i - 1, j - 1]) / (d[i + j, - 1] - d[i - j, - 1])]]
dif // MatrixForm
n k-1
poliNewt =  d[k, k]  x - xj  // Expand
k=0 j=0

Round[poliNewt /. x → xint]

Part::partd : Part specification {{-5, 1}, {-3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, -3}}〚0, 1〛 is longer than depth of object. 
yk xk
{{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛 1
1
-5-{{-5,1},{-3,2},{2,10},{3,2},{6,

-5 2

-3 10

8
-5

2 2

-2

3 0
-1
6 -3
6 111111111111111111111111111111111111111.nb

x
1+ + ⋯ 164 ⋯
⋯1⋯

large output show less show more show all set size limit...

Round[1 - 3 / (- 5 - {{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛) -
24 / (- 3 - {{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛) +
6 / ((- 5 - {{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛)
(- 3 - {{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛)) -
{{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛 /
(- 5 - {{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛) -
(8 {{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛) /
(- 3 - {{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛) +
(2 {{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛) /
((- 5 - {{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛)
(- 3 - {{- 5, 1}, {- 3, 2}, {2, 10}, {3, 2}, {6, 0}, {8, - 3}}〚0, 1〛))]

1
4 sea la funcion f (x) definido en el intervalo[- 5, 5]
1 + x2
111111111111111111111111111111111111111.nb 7

1
f[x_] :=
1 + x2
Plot[f[x], {x, - 2, 2},
PlotRange → {{- 2, 2}, {- 25, 5}}]
x0 = - 5;(*punto de inicio*)
n = 6;(*numero de interaciones*)
m = 5;(*nuemro de decimales*)
t = SetPrecision;
Plot[f[x], {x, x0 - 1, x0 + 1}];
(*inicio del programa*)
f[xi-1 ]
Fori = 0, i ≤ n, xi = xi-1 - ,
∂x f[x] /. x -> xi-1
i = i + 1(*fin del programa*)
TableForm[Table[{i, t[xi , m]}, {i, 0, n}], TableHeadings → {None, {"i", " xi "}}]

-2 -1 1 2

-5

-10

-15

-20

-25

i xi
0 - 5.0000
1 - 7.6000
2 - 11.466
3 - 17.242
4 - 25.892
5 - 38.858
6 - 58.300

Anda mungkin juga menyukai