0% found this document useful (0 votes)
24 views

% Grafica de La F y de Su Polinomio de Lagrange

The document discusses using Lagrange polynomials to fit data points. It generates data points and finds the Lagrange polynomial that fits the data. It then plots the original function and Lagrange polynomial to compare them. This is repeated for different data sets.

Uploaded by

Romain Díaz
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

% Grafica de La F y de Su Polinomio de Lagrange

The document discusses using Lagrange polynomials to fit data points. It generates data points and finds the Lagrange polynomial that fits the data. It then plots the original function and Lagrange polynomial to compare them. This is repeated for different data sets.

Uploaded by

Romain Díaz
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

5

clc
clear
X=[-2 0 2 4]
Y=exp(X./4).*(X-3).^2
[C, L] = lagrange(X,Y)
% grafica de la f y de su polinomio de lagrange
x=[-2:0.001:4];
y=exp(x./4).*(x-3).^2
y1=polyval(C,x)
plot(x,y,'k','linewidth',2)
hold on
plot(x,y1,'r','linewidth',2)
hold off
grid on
a=polyval(C,2.7)

>> X=[-2 0 2 4]

X=

-2 0 2 4

>> Y=exp(X./4).*(X-3).^2

Y=

15.163 9 1.6487 2.7183

>> Y=exp(X./4).*(X-3).^2

Y=

15.163 9 1.6487 2.7183

>> [C, L] = lagrange(X,Y)

C=

0.20018X^3 -0.1485X^2 -4.1794X 9

L=

-0.020833 0.125 -0.16667 0

0.0625 -0.25 -0.25 1

-0.0625 0.125 0.5 0

0.020833 0 -0.083333 0
a =
0.57334
16

14

12

10

0
-2 -1 0 1 2 3 4

6
6.1)

clc
clear
X=[-2 6]
Y=1/4*X.^3-7*X.^2+10*X-15
[C, L] = lagrange(X,Y)
% grafica de la f y de su polinomio de lagrange
x=[-2:0.001:6];
y=1/4*x.^3-7*x.^2+10*x-15
y1=polyval(C,x)
plot(x,y,'k','linewidth',2)
hold on
plot(x,y1,'r','linewidth',2)
hold off
grid on
>> X=[-2 6]

X=

-2 6

>> Y=1/4*X.^3-7*X.^2+10*X-15

Y=

-65 -153

>> [C, L] = lagrange(X,Y)

C=

-11X^2 -87

L=

-0.125 0.75

0.125 0.25

-20

-40

-60

-80

-100

-120

-140

-160
-2 -1 0 1 2 3 4 5 6
6.2)
clc
clear
X=[-2 2 6]
Y=1/4*X.^3-7*X.^2+10*X-15
[C, L] = lagrange(X,Y)
% grafica de la f y de su polinomio de lagrange
x=[-2:0.001:6];
y=1/4*x.^3-7*x.^2+10*x-15
y1=polyval(C,x)
plot(x,y,'k','linewidth',2)
hold on
plot(x,y1,'r','linewidth',2)
hold off
grid on

>> X=[-2 2 6]

X=

-2 2 6

>> Y=1/4*X.^3-7*X.^2+10*X-15

Y=

-65 -21 -153

>> [C, L] = lagrange(X,Y)

C=

-5.5x^2 11x -21

L=

0.03125 -0.25 0.375

-0.0625 0.25 0.75

0.03125 0 -0.125
0

-20

-40

-60

-80

-100

-120

-140

-160
-2 -1 0 1 2 3 4 5 6

6.3)

>> X=[-2 0 2 4 6]

X=

-2 0 2 4 6

>> Y=1/4*X.^3-7*X.^2+10*X-15

Y=

-65 -15 -21 -71 -153

>> [C, L] = lagrange(X,Y)

C=

0x^4 0.25x^3 -7x^2 10x -15

L=

0.0026042 -0.03125 0.11458 -0.125 0

-0.010417 0.10417 -0.20833 -0.41667 1


0.015625 -0.125 0.0625 0.75 0

-0.010417 0.0625 0.041667 -0.25 0

0.0026042 -0.010417 -0.010417 0.041667 0

-20

-40

-60

-80

-100

-120

-140

-160
-2 -1 0 1 2 3 4 5 6

You might also like