0% encontró este documento útil (0 votos)
173 vistas19 páginas

Interpolación de Polinomios en MATLAB

Este documento presenta los resultados de una tarea sobre interpolación. Se realizó la interpolación de datos experimentales sobre la velocidad de sedimentación de una suspensión de carbonato de calcio utilizando polinomios de interpolación de Newton. Se determinaron los coeficientes del polinomio cúbico que pasa por los primeros cuatro puntos de datos y se calculó la velocidad de sedimentación para una concentración del 2.5%.
Derechos de autor
© All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
173 vistas19 páginas

Interpolación de Polinomios en MATLAB

Este documento presenta los resultados de una tarea sobre interpolación. Se realizó la interpolación de datos experimentales sobre la velocidad de sedimentación de una suspensión de carbonato de calcio utilizando polinomios de interpolación de Newton. Se determinaron los coeficientes del polinomio cúbico que pasa por los primeros cuatro puntos de datos y se calculó la velocidad de sedimentación para una concentración del 2.5%.
Derechos de autor
© All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd

UNIVERSIDAD MAYOR DE SAN ANDRÉS

FACULTAD DE INGENIERÍA
PROGRAMACIÓN Y MÉTODOS NUMÉRICOS

NOMBRE: Gozalvez Carvajal Melani Aida


TÍTULO DE LA PRÁCTICA: Tarea 8
CARRERA: Ing. Química
NOMBRE DEL DOCENTE: Ing. Roberto Parra
FECHA DE REALIZACIÓN: 12/09/21
FECHA DE ENTREGA: 14/09/21
PRÁCTICA
PRQ404 – INTERPOLACIÓN
1.- Dados los datos:

x 1 2 3 5 7 8
f(x) 3 6 19 99 291 444

Calcule f(4) con el uso de polinomios de interpolación de Newton de órdenes 1 a 4. Elija los puntos base
para obtener una buena exactitud. ¿Qué indican los resultados en relación con el orden del polinomio
que se emplea para generar los datos de la tabla?

PSEUDOCÓDIGO DIAGRAMA DE FLUJO


1. INICIO
2. function [C,D] = difdivabs(X,Y)
3. Hacer n=length(X);
4. Hacer D=zeros(n,n);
5. Hacer D(:,1)=Y';
6. Para j=2:n
7. Para k=j:n
8. Hacer D(k,j)=(D(k,j-1)-D(k-1,j-1))/(X(k)-
X(k-j+1));
9. Fin Para
10. Fin Para
11. Hacer C=D(n,n);
12. Para k=(n-1):-1:1
13. Hacer C=conv(C,poly(X(k)));
14. Hacer m=length(C);
15. Hacer C(m)=C(m)+D(k,k);
16. Fin Para
17. FIN

PROGRAMA EN MATLAB
function [C,D] = difdivabs(X,Y)
%-------
%Este programa realiza la
interpolación de un conjunto de
puntos (x,y)
%por el metodo de diferencias
divididas hacia abajo
%--------------
%ENTRADAS
% x : Conjunto de abcisas
% y : Conjunto
%SALIDAS
% C : Coeficientes del
polinomio interpolante de Newton
% D : Coeficientes de la
tabla por el método de diferencias
%--------------------------
n=length(X); INICIO
D=zeros(n,n);
D(:,1)=Y';%todas las filas, pero
solo la 1ra. columna
%Formula de la tabla de diferencia function [C,D] = difdivabs(X,Y)
divididasd hacia abajo.
for j=2:n
for k=j:n
D(k,j)=(D(k,j-1)-D(k-1,j- n=length(X)
1))/(X(k)-X(k-j+1));
end
end
%Determinando los coeficientes de D=zeros(n,n)
los polinomios interpolantes de D(:,1)=Y'
Newton
C=D(n,n);
for k=(n-1):-1:1 j=2;j=j+1;j=<n
C=conv(C,poly(X(k)));
m=length(C);
C(m)=C(m)+D(k,k);
end
k=j;k=k+1;k=<n

end
D(k,j)=(D(k,j-1)-D(k-1,j-1))/(X(k)-X(k-j+1))
RESULTADOS
>> X=[1 2 3 5 7 8]
k
X=

1 2 3 5 7 8
j

>> Y=[3 6 19 99 291 444]

Y= k=(n-1):-1:1

3 6 19 99 291 444
C=conv(C,poly(X(k)))
>> [C,D] = difdivabs(X,Y) m=length(C)
C(m)=C(m)+D(k,k)
C=

0 0 1 -1 -1 4 k

C
D=

3 0 0 0 0 0
6 3 0 0 0 0 FIN
19 13 5 0 0 0
99 40 9 1 0 0
291 96 14 1 0 0
444 153 19 1 0 0

>> P=poly2sym(C)

P=

x^3 - x^2 - x + 4

>> f=inline(P)

f=

Inline function:
f(x) = -x-x.^2+x.^3+4.0

>> f(4)

ans =

48

2.- Determine los coeficientes de la ecuación cúbica que pasa por los primeros cuatro puntos del
problema anterior.

PSEUDOCÓDIGO DIAGRAMA DE FLUJO


1. INICIO
2. function [C,D] = difdivabs(X,Y)
3. Hacer n=length(X);
4. Hacer D=zeros(n,n);
5. Hacer D(:,1)=Y';
6. Para j=2:n
7. Para k=j:n
8. Hacer
D(k,j)=(D(k,j-1)-D(k-1,j-1))/(X(k)-X(k-
j+1));
9. Fin Para
10. Fin Para
11. Hacer C=D(n,n);
12. Para k=(n-1):-1:1
13. Hacer C=conv(C,poly(X(k)));
14. Hacer m=length(C);
15. Hacer C(m)=C(m)+D(k,k);
16. Fin Para
17. FIN
PROGRAMA EN MATLAB
function [C,D] = difdivabs(X,Y) INICIO
%-------
%Este programa realiza la
interpolación de un conjunto de
puntos (x,y) function [C,D] = difdivabs(X,Y)
%por el metodo de diferencias
divididas hacia abajo
%--------------
%ENTRADAS n=length(X)
% x : Conjunto de abcisas
% y : Conjunto
%SALIDAS
% C : Coeficientes del
D=zeros(n,n)
polinomio interpolante de Newton D(:,1)=Y'
% D : Coeficientes de la
tabla por el método de
diferencias j=2;j=j+1;j=<n
%--------------------------
n=length(X);
D=zeros(n,n);
D(:,1)=Y';%todas las filas, pero k=j;k=k+1;k=<n
solo la 1ra. columna
%Formula de la tabla de
diferencia divididasd hacia
abajo. D(k,j)=(D(k,j-1)-D(k-1,j-1))/(X(k)-X(k-j+1))
for j=2:n
for k=j:n
D(k,j)=(D(k,j-1)-D(k-
1,j-1))/(X(k)-X(k-j+1)); k
end
end
%Determinando los coeficientes
de los polinomios interpolantes j
de Newton
C=D(n,n);
for k=(n-1):-1:1
C=conv(C,poly(X(k))); k=(n-1):-1:1
m=length(C);
C(m)=C(m)+D(k,k);
end
C=conv(C,poly(X(k)))
m=length(C)
end C(m)=C(m)+D(k,k)

RESULTADOS
k
>> X=[1 2 3 5 7 8]

X= C

1 2 3 5 7 8

>> Y=[3 6 19 99 291 444] FIN


Y=

3 6 19 99 291 444

>> [C,D] = difdivabs(X,Y)

C=

0 0 1 -1 -1 4

D=

3 0 0 0 0 0
6 3 0 0 0 0
19 13 5 0 0 0
99 40 9 1 0 0
291 96 14 1 0 0
444 153 19 1 0 0

>> P=poly2sym(C)

P=

x^3 - x^2 - x + 4

3.- La velocidad de sedimentación de una suspensión, se relaciona con la concentración volumétrica del
sedimento. Los datos experimentales para la sedimentación de una suspensión de precipitado de
carbonato de calcio se muestran en la tabla adjunta. Se requiere:

a) Encontrar la ecuación del polinomio interpolante que pase por los datos experimentales.
b) Calcular la velocidad de sedimentación para una concentración volumétrica de 2.5%.

Conc. Vol, % 0.00 1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00

Vel. Sediment, g/cm2hr 0.00 3.20 4.80 4.25 3.23 2.87 2.75 2.70 2.65

PSEUDOCÓDIGO DIAGRAMA DE FLUJO


1. INICIO
2. function [C,D] = difdivabs(X,Y)
3. Hacer n=length(X);
4. Hacer D=zeros(n,n);
5. Hacer D(:,1)=Y';
6. Para j=2:n
7. Para k=j:n
8. Hacer D(k,j)=(D(k,j-1)-D(k-1,j-1))/(X(k)-X(k-
INICIO
j+1));
9. Fin Para
10. Fin Para
11. Hacer C=D(n,n); function [C,D] = difdivabs(X,Y)
12. Para k=(n-1):-1:1
13. Hacer C=conv(C,poly(X(k)));
14. Hacer m=length(C);
15. Hacer C(m)=C(m)+D(k,k); n=length(X)
16. Fin Para
17. FIN
D=zeros(n,n)
PROGRAMA EN MATLAB
D(:,1)=Y'
function [C,D] = difdivabs(X,Y)
%-------
%Este programa realiza la interpolación j=2;j=j+1;j=<n
de un conjunto de puntos (x,y)
%por el metodo de diferencias divididas
hacia abajo
%-------------- k=j;k=k+1;k=<n
%ENTRADAS
% x : Conjunto de abcisas
% y : Conjunto
%SALIDAS D(k,j)=(D(k,j-1)-D(k-1,j-1))/(X(k)-X(k-j+1))
% C : Coeficientes del polinomio
interpolante de Newton
% D : Coeficientes de la tabla
por el método de diferencias k
%--------------------------
n=length(X);
D=zeros(n,n);
D(:,1)=Y';%todas las filas, pero solo j
la 1ra. columna
%Formula de la tabla de diferencia
divididasd hacia abajo.
for j=2:n k=(n-1):-1:1
for k=j:n

D(k,j)=(D(k,j-1)-D(k-1,j-1))/(X(k)-X(k- C=conv(C,poly(X(k)))
j+1));
end
m=length(C)
end C(m)=C(m)+D(k,k)
%Determinando los coeficientes de los
polinomios interpolantes de Newton
C=D(n,n); k
for k=(n-1):-1:1
C=conv(C,poly(X(k)));
m=length(C); C
C(m)=C(m)+D(k,k);
end
end
FIN
RESULTADOS
>> X=[0 1 2 3 4 5 6 7 8]

X=

Columns 1 through 8

0 1 2 3 4 5 6 7

Column 9

>> Y=[0 3.20 4.80 4.25 3.23 2.87 2.75 2.70 2.65]

Y=

Columns 1 through 4

0 3.2000 4.8000 4.2500

Columns 5 through 8

3.2300 2.8700 2.7500 2.7000

Column 9

2.6500

>> [C,D] = difdivabs(X,Y)

C=

Columns 1 through 4

-0.0001 0.0042 -0.0479 0.2557

Columns 5 through 8

-0.5827 0.1917 0.1057 3.2735

Column 9

D=

Columns 1 through 4
0 0 0 0
3.2000 3.2000 0 0
4.8000 1.6000 -0.8000 0
4.2500 -0.5500 -1.0750 -0.0917
3.2300 -1.0200 -0.2350 0.2800
2.8700 -0.3600 0.3300 0.1883
2.7500 -0.1200 0.1200 -0.0700
2.7000 -0.0500 0.0350 -0.0283
2.6500 -0.0500 -0.0000 -0.0117

Columns 5 through 8

0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0.0929 0 0 0
-0.0229 -0.0232 0 0
-0.0646 -0.0083 0.0025 0
0.0104 0.0150 0.0039 0.0002
0.0042 -0.0013 -0.0027 -0.0009

Column 9

0
0
0
0
0
0
0
0
-0.0001

>> V=poly2sym(C)

V=

-
(2639824238722827*x^8)/18446744073709551616
+ (4853021769887763*x^7)/1152921504606846976
- (3448506314669319*x^6)/72057594037927936 +
(18407*x^5)/72000 -
(2624277214116349*x^4)/4503599627370496 +
(6905769628614417*x^3)/36028797018963968 +
(3808508342025039*x^2)/36028797018963968 +
(91657*x)/28000
>> V=inline(V)

V=

Inline function:
V(x) =
x.*3.273464285714286+x.^2.*1.057073412698295e
-1+x.^3.*1.916736111111211e-1-
x.^4.*5.827065972222265e-
1+x.^5.*2.556527777777778e-1-
x.^6.*4.785763888888904e-
2+x.^7.*4.209325396825408e-3-
x.^8.*1.431051587301591e-4

>> V(2.5)

ans =

4.7102

4.- La potencia generada por un molino de viento varía con la velocidad del viento. En un experimento,
se obtuvieron las cinco mediciones siguientes:

velocidad, km/h 22.53 35.41 48.28 61.15 74.03


Potencia, W 320 490 540 500 480

Determine el polinomio de Lagrange de 4to. orden que pase por los cinco puntos. Usando este
polinomio calcular la potencia a una velocidad de viento de 42 km/hr.

PSEUDOCÓDIGO DIAGRAMA DE FLUJO


1. INICIO
2. function [C] = lagran(X,Y)
3. Hacer n1=length(X);
4. Hacer n=n1-1;
5. Hacer L=zeros(n1,n1);
6. Para k=1:n+1,
7. Hacer V=1;
8. Para j=1:n+1,
9. Si k~=j
10. Hacer V=conv(V,poly(X(j)))/(X(k)-X(j));
11. Fin si
12. Fin Para
13. Hacer L(k,:)=V;
14. Fin Para
15. Hacer C=Y*L;
16. FIN
INICIO

PROGRAMA EN MATLAB
function [C] = lagran(X,Y)
%------------------------------- function [C] = lagran(X,Y)
%Este programa realiza la interpolación de
Lagrange a un conjunto de
% puntos (x,y) y muestra la lista de n1=length(X);
coeficientes del polinomio n=n1-1;
% interpolante L=zeros(n1,n1)
% ENTRADAS
% X : Vector de las abcisas
% Y : Vector de las ordenadas
% SALIDAS k=1;k=k+1;k<n+1
% C : Lista de coeficientes del
polinomio de Lagrange
%-----------------------------------
n1=length(X); V=1
n=n1-1;
L=zeros(n1,n1);
for k=1:n+1,
V=1; j=1; j=j+1; j<n+1
for j=1:n+1,
if k~=j
NO
V=conv(V,poly(X(j)))/(X(k)-
X(j));
end k~=j
end
L(k,:)=V; SI
end
C=Y*L;
end V=conv(V,poly(X(j)))/(X(k)-X(j))

RESULTADOS
>> X=[22.53 35.41 48.28 61.15 74.03] j

X=
L(k,:)=V
22.5300 35.4100 48.2800 61.1500 74.0300

>> Y=[320 490 540 500 480]


k

Y=

320 490 540 500 480 C=Y*L

>> [C] = lagran(X,Y)


C
C=

0.0001 -0.0180 0.6187 11.0931 -69.0629 FIN


>> P=poly2sym(C)

P=

(140311507112827*x^4)/1152921504606846976 -
(20309136268297*x^3)/1125899906842624 +
(1360600532165*x^2)/2199023255552 +
(97575570550203*x)/8796093022208 -
75935472333177/1099511627776

>> P=inline(P)

P=

Inline function:
P(x) =
x.*1.109305805473502e+1+x.^2.*6.187294876167471e-
1-x.^3.*1.803813655625053e-
2+x.^4.*1.217008326691539e-4-
6.906290976364926e+1

>> P(42)

ans =

530.5709

6.- Emplee la porción de la tabla de vapor que se da para el H2O supercalentada a 200 MPa, para:
a) encontrar la entropía correspondiente S para un volumen específico v de 0.108 m3 /kg con
interpolación lineal, b) encontrar la misma entropía correspondiente con el uso de interpolación
cuadrática, y c) hallar el volumen correspondiente a una entropía de 6.6 con el empleo de interpolación
inversa.

v (m3/kg) 0.10377 0.11144 0.1254


S (kJ/kg · K) 6.4147 6.5453 6.7664

PSEUDOCÓDIGO DIAGRAMA DE FLUJO


1. INICIO
2. function [C] = lagran(X,Y)
3. Hacer n1=length(X);
4. Hacer n=n1-1;
5. Hacer L=zeros(n1,n1);
6. Para k=1:n+1,
7. Hacer V=1;
8. Para j=1:n+1,
9. Si k~=j
INICIO
10. Hacer V=conv(V,poly(X(j)))/(X(k)-X(j));
11. Fin si
12. Fin Para
function [C] = lagran(X,Y)
13. Hacer L(k,:)=V;
14. Fin Para
15. Hacer C=Y*L; n1=length(X);
16. FIN n=n1-1;
L=zeros(n1,n1)
PROGRAMA EN MATLAB
%P8-E6
clc
clear all
k=1;k=k+1;k<n+1
X=input('lea el conjunto de
abcisas\n');
Y=input('lea el conjunto de
V=1
ordenadas\n');
[C,P]=Lagrange(X,Y)
fprintf('¿Quiere evaluar la funcion
en algun punto?\n')
l=input('ingrese 1 si quiere evaluar j=1; j=j+1; j<n+1
la funcion\n');
if l==1 NO
EV=inline(P);
r=input('ingrese el punto a
evaluar\n');
k~=j
q=EV(r);
fprintf('la funcion evaluada es: SI
%4.3f \n',q)
end V=conv(V,poly(X(j)))/(X(k)-X(j))
PROGRAMA FUNCTION EN MATLAB
function [C] = lagran(X,Y)
%-------------------------------
%Este programa realiza la j
interpolación de Lagrange a un
conjunto de
% puntos (x,y) y muestra la lista de
coeficientes del polinomio L(k,:)=V
% interpolante
% ENTRADAS
% X : Vector de las abcisas
% Y : Vector de las ordenadas k
% SALIDAS
% C : Lista de coeficientes del
polinomio de Lagrange
%----------------------------------- C=Y*L
n1=length(X);
n=n1-1;
L=zeros(n1,n1);
C
for k=1:n+1,
V=1;
for j=1:n+1,
if k~=j
FIN
V=conv(V,poly(X(j)))/(X(k)-X(j));
end
end
L(k,:)=V;
end
C=Y*L;
end

7.- Desarrolle, depure y pruebe un sub-programa (function) en MATLAB, para encontrar un polinomio
interpolante de grado n y el valor de f(x) para cualquier x en el intervalo [x min, xmax]. Formule un Programa
interactivo en GUIDE. Pruebe el programa con los datos del ejercicio 4. a) Usando el método de
Lagrange, b) Para el método de Newton.

Sugerencia - Argumentos: (x, y, n, xp)

xp es el valor de x para encontrar su valor de yp.

PROGRAMA EN MATLAB
function varargout = P8_E7(varargin)
% P8_E7 MATLAB code for P8_E7.fig
% P8_E7, by itself, creates a new P8_E7 or raises the existing
% singleton*.
%
% H = P8_E7 returns the handle to a new P8_E7 or the handle to
% the existing singleton*.
%
% P8_E7('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in P8_E7.M with the given input arguments.
%
% P8_E7('Property','Value',...) creates a new P8_E7 or raises the
% existing singleton*. Starting from the left, property value pairs
are
% applied to the GUI before P8_E7_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to P8_E7_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help P8_E7

% Last Modified by GUIDE v2.5 21-Nov-2021 17:31:46

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @P8_E7_OpeningFcn, ...
'gui_OutputFcn', @P8_E7_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before P8_E7 is made visible.


function P8_E7_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to P8_E7 (see VARARGIN)

% Choose default command line output for P8_E7


[Link] = hObject;

% Update handles structure


guidata(hObject, handles);
set(handles.edit1,'String',' ')
set(handles.edit2,'String',' ')
set(handles.edit5,'String',' ')
set(handles.edit6,'String',' ')
set(handles.edit7,'String',' ')

% UIWAIT makes P8_E7 wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = P8_E7_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = [Link];

function edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text


% str2double(get(hObject,'String')) returns contents of edit1 as a
double

% --- Executes during object creation, after setting all properties.


function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit2_Callback(hObject, eventdata, handles)


% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text


% str2double(get(hObject,'String')) returns contents of edit2 as a
double

% --- Executes during object creation, after setting all properties.


function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes during object creation, after setting all properties.


function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit4_Callback(hObject, eventdata, handles)


% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text


% str2double(get(hObject,'String')) returns contents of edit4 as a
double

% --- Executes during object creation, after setting all properties.


function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
X=get(handles.edit1,'String');
Y=get(handles.edit2,'String');
[C] = lagran(X,Y)
P=poly2sym(C);
P=inline(P);
x=str2double(get(handles.edit7,'String'));
Ans=P(x)
set(handles.edit5,'String',Ans)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text


% str2double(get(hObject,'String')) returns contents of edit5 as a
double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text


% str2double(get(hObject,'String')) returns contents of edit6 as a
double

% --- Executes during object creation, after setting all properties.


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
X=get(handles.edit1,'String');
Y=get(handles.edit2,'String');
[C,D] = difdivabs(X,Y)
P=poly2sym(C);
P=inline(P);
x=str2double(get(handles.edit7,'String'));
set(handles.edit6,'String',P(x))
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit7_Callback(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text


% str2double(get(hObject,'String')) returns contents of edit7 as a
double

% --- Executes during object creation, after setting all properties.


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

8.- Cual es la diferencia entre ajuste de curvas por mínimos cuadrados (suavisado de curvas) y
interpolación polinómica de Lagrange? Que usos tiene cada uno?

Algunas suposiciones estadísticas, inherentes a los procedimientos lineales por mínimos cuadrados, son
1. Cada x tiene un valor fijo; no es aleatorio y se conoce sin error.

2. Los valores de y son variables aleatorias independientes y todas tienen la misma varianza.

3. Los valores de y para una x dada deben estar distribuidos normalmente.

Tales suposiciones son relevantes para la obtención adecuada y el uso de la regresión.

Cuando se va a ejecutar sólo una interpolación, las formulaciones de Lagrange y de Newton requieren
un trabajo computacional semejante. No obstante, la versión de Lagrange es un poco más fácil de
programar. Debido a que no requiere del cálculo ni del almacenaje de diferencias divididas, la forma de
Lagrange a menudo se utiliza cuando el grado del polinomio se conoce a priori.

También podría gustarte