Polynomial and interpolation.pdf
-
Upload
pako-rodriguez -
Category
Documents
-
view
46 -
download
0
Transcript of Polynomial and interpolation.pdf
![Page 1: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/1.jpg)
Polynomial and
interpolation
Technological University of Leon
Dr. J. Guadalupe Santos Gómez
![Page 2: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/2.jpg)
Representing polynomials Polinomial are represented as vector of their coefficients, so
𝑓 𝑥 = 𝑥4 − 3𝑥3 + 2𝑥2 − 5𝑥 + 8 is simply
p=[1 -3 2 -5 8]
And the roots of this polynomial
>> p=[1 -3 2 -5 8];roots(p)
ans =
-0.4860 + 1.3883i
-0.4860 - 1.3883i
2.4829 + 0.0000i
1.4892 + 0.0000i
![Page 3: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/3.jpg)
Evaluating polynomials
You can evaluate a polynomial at one or more points with the
polyval function. The polyval function evaluates a polynomial at
a specified value. To evaluate p at x = 5, use >> polyval(p,5)
ans =
283
>> x = -1:2 ;
y = polyval(p,x)
y =
19 8 3 -2
![Page 4: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/4.jpg)
You can construct a symbolic polynomial from the coefficient vector p and back again: >> syms x
f = poly2sym(p)
sym2poly(f)
f =
x^4 - 3*x^3 + 2*x^2 - 5*x + 8
![Page 5: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/5.jpg)
>> X = [2 4 5; -1 0 3; 7 1 5];
Y = polyvalm(p,X)
Y =
2638 1438 3458
842 326 1092
3880 1966 4702
![Page 6: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/6.jpg)
>> f=[3 -3 0 2 7];g=[1 -2 0 8];%Multiplicación >> c=conv(f,g) c = 3 -9 6 26 -21 -14 16 56 >> [q,r]=deconv(f,g)%División q = 3 3 r = 0 0 6 -22 -17
![Page 7: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/7.jpg)
multiplication and division
Multiplication of polinomials
𝑓 𝑥 = 𝑥3 − 3𝑥2 + 2𝑥 − 8 𝑔 𝑥 = 2𝑥2 − 𝑥 + 5
>> f=[1 -3 2 -8];g=[2 -1 5];%multiplicación
>> c=conv(f,g)
c =
2 -7 12 -33 18 -40
![Page 8: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/8.jpg)
>> f=[1 -3 2 -8];g=[2 -1 5];%división
>> [q,r]=deconv(f,g)
q =
0.5000 -1.2500
r =
0 0 -1.7500 -1.7500
q and r are the quotient and remainder
![Page 9: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/9.jpg)
Polynomial interpolation
Polynomials are useful as easier-to-compute approximations of
more complicated functions, via a Taylor series expansion or by
a low-degree best-fit polynomial using the polyfit function. The
statement:
p=polyfit(x,y,n)
finds the best-fit n-degree polynomial that approximates the data
points x and y. Try this example:
![Page 10: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/10.jpg)
x = 0:.1:pi ;
y = sin(x) ;
p = polyfit(x, y, 5)
figure(1) ; clf
ezplot(@sin, [0 pi])
hold on
xx = 0:.1:pi ;
plot(xx, polyval(p,xx), 'r*')
p =
0.0002 0.0359 -0.2296 0.0487 0.9860 0.0007
0 0.5 1 1.5 2 2.5 3
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
x
sin
![Page 11: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/11.jpg)
p = polyfit(x,y,n) finds the coefficients of a
polynomial p(x) of degree n that fits the data,
p(x(i)) to y(i), in a least squares sense. The result
p is a row vector of length n+1 containing the
polynomial coefficients in descending powers:
![Page 12: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/12.jpg)
Interpolation
![Page 13: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/13.jpg)
Interpolación lineal interp1(x,y,’method’)
x: abscissa of the points to be interpolated, expressed as a vector row.
y: ordinate of the points to be interpolated, expressed as a vector row.
xi: abscissa to construct the interpolation function, expressed as a vector row.
If a single value, calculate the interpolation methods with declared value
function.
Method, determines the interpolation method. This is an optional specification
that indicates the interpolation method.
![Page 14: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/14.jpg)
y1 = 64.8000 y2 = 106.7000
clc clear all x=0:5; T=[0 20 60 68 77 110]; y1=interp1(x,T,2.6) y2=interp1(x,T,4.9)
Calculation of two interpolated values for two values of x between 0 and 5
If the second term of the interp1 function is an array, the array returns a row vector with the same number of rows and each returned value is interpolated from the column corresponding data
clc clear all x(:,1)=(0:5) T(:,1)=[0 20 60 68 77 110] T(:,2)=[0 25 62 67 82 103] T(:,3)=[0 52 90 91 93 96] tems=interp1(x,T,2.6)
![Page 15: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/15.jpg)
clc clear all x(:,1)=(0:5) T(:,1)=[0 20 60 68 77 110] T(:,2)=[0 25 62 67 82 103] T(:,3)=[0 52 90 91 93 96] tems=interp1(x,T,2.6)
temps = 64.8000 65.0000 90.6000
Datos interpolados
![Page 16: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/16.jpg)
interp1(x,y,x_new,’spline’) devuelve un vector columna que
contiene los valores y interpolados que corresponden a x_new usando interpolación spline cúbica
Interpolación cúbica
clc
clear all
x=0:5;
T=[0 20 60 68 77 110];
x1=0:0.1:5;
T1=interp1(x,T,x1,'linear')
T2=interp1(x,T,x1,'spline')
plot(x1,T1,x1,T2,x,T,'o')
axis([-1,6,20,120])
-1 0 1 2 3 4 5 620
30
40
50
60
70
80
90
100
110
120
Muestra
Tem
pera
tura
linear
spline cúbico
medidas
![Page 17: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/17.jpg)
Polynomial curve fitting
Clc clear all %ajuste de cruvas x=1:5; y=[5.5 43.1 128 290.7 498.4]; % Third-order polynomial fit p3=polyfit(x,y,3) x1=1:0.1:5; y2=polyval(p3,x1); plot(x,y,'o',x1,y2)
1 1.5 2 2.5 3 3.5 4 4.5 50
50
100
150
200
250
300
350
400
450
500
Muestra
Tem
pera
tura
Ajuste polinomial de curvas
32 1917.05821.316262.6034.35 xxxy
p3 = -0.1917 31.5821 -60.3262 35.3400
![Page 18: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/18.jpg)
clc clear all %Ajuste de datos x=linspace(0,pi,50); %introduce un error al seno del 1% f=sin(x)+0.01*rand(1,length(x)); %Ajusta los datos p=polyfit(x,f,4); g=polyval(p,x); %Dibuja los datos y su respectivo ajuste plot(x,f,'r*',x,g,'b-') grid
0 0.5 1 1.5 2 2.5 3 3.50
0.2
0.4
0.6
0.8
1
1.2
1.4
![Page 19: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/19.jpg)
clear all
Clc
t = [0 .3 .8 1.1 1.6 2.3]';
y = [.82 .72 .63 .60 .55 .50]';
E = [ones(size(t)) exp(-t)]
C=E\y
T = (0:0.1:2.5)';
Y = [ones(size(T)) exp(-T)]*C;
plot(T,Y,'-',t,y,'o')
E = 1.0000 1.0000 1.0000 0.7408 1.0000 0.4493 1.0000 0.3329 1.0000 0.2019 1.0000 0.1003 C = 0.4760 0.3413
teccty 21)(
tety 3413.04760.0)(
0 0.5 1 1.5 2 2.50.5
0.55
0.6
0.65
0.7
0.75
0.8
0.85
0.9Función de decaimiento exponencial
Tiempo [s]
Am
plit
ud
simulado
datos
Regresión exponencial
![Page 20: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/20.jpg)
El editor en jefe de un importante periódico metropolitano ha intentado convencer al dueño para que mejore las condiciones de trabajo en la imprenta. Está convencido de que, cuando trabajan las prensas, el grado de ruido crea niveles no saludables de tensión y ansiedad. Recientemente hizo que un sicólogo realizara una prueba durante la cual situaron a los prensistas en cuartos con niveles variables de ruido y luego les hicieron otra prueba para medir niveles de humor y ansiedad. La siguiente tabla muestra el índice de su grado de ansiedad o nerviosismo y el nivel de ruido al que se vieron expuestos (1.0 es bajo y 10.0 es alto). Nivel de ruido 4 3 1 2 6 7 2 3 Grado de ansiedad 39 38 16 18 41 45 25 38 a) Grafique estos datos. b) Desarrolle una ecuación de estimación que describa los datos. c) Pronostique el grado de ansiedad que podríamos esperar cuando el nivel de ruido es 5.
![Page 21: Polynomial and interpolation.pdf](https://reader033.fdocuments.in/reader033/viewer/2022051117/55cf8fb9550346703b9f2ea5/html5/thumbnails/21.jpg)
Un productor de comida para cerdos desea determinar qué relación existe entre la edad de un cerdo cuando empieza a recibir un complemento alimenticio de reciente creación, el peso inicial del animal y el aumento de peso en un periodo de una semana con el complemento alimenticio. La siguiente información es resultado de un estudio de ocho lechones: X1 X2 Y Número Peso inicia l Edad inicial Aumento de lechón (libras) (semanas) de peso 1 39 8 7 2 52 6 6 3 49 7 8 4 46 12 10 5 61 9 9 6 35 6 5 7 25 7 3 8 55 4 4 a) Calcule la ecuación de mínimos cuadrados que mejor describa estas tres variables. b) ¿Cuánto podemos esperar que un cerdo aumente de peso en una semana con el complemento alimenticio, si tenía nueve semanas de edad y pesaba 48 libras?