Sie sind auf Seite 1von 6

ESCUELA POLITECNICA NACIONAL

INGENIERIA MECANICA

ANALISIS NUMERICO

NOMBRE: ALEX QUINGA

CURSO: GR-1

DERIVADAS
% Alex Quinga
%06/23/2019
% DERIVADAS
%este preograma nos permite hallar la primera y la segunda derivada de una
%funcion desconocidaa traves del concepto de diferencias divididas
%datos de entrada
x=[2.5 2.55 2.6 2.65 2.70 2.75];
y=[1.58114 1.59687 1.61245 1.62788 1.64317 1.65831];
a=2.5; %punto donde se evalua
plot(x,y)
hold on
%Primera Derivada
y11=(y(1)-y(2))/(x(1)-x(2));%f(x0,x1)
y12=(y(2)-y(3))/(x(2)-x(3));%f(x1,x2)
y13=(y(3)-y(4))/(x(3)-x(4));%f(x2,x3)
y14=(y(4)-y(5))/(x(4)-x(5));%f(x3,x4)
y15=(y(5)-y(6))/(x(5)-x(6));%f(x4,x5)
Derivada_11=[y11 y12 y13 y14 y15];
Derivada_1=mean(Derivada_11) %valor de la primera derivada
%Segunda Derivada
y21=(y11-y12)/(x(1)-x(3));%f(x0,x1,x2)
y22=(y12-y13)/(x(2)-x(4));%f(x1,x2,x3)
y23=(y13-y14)/(x(3)-x(5));%f(x2,x3,x4)
y24=(y14-y15)/(x(4)-x(6));%f(x3,x4,x5)
Derivada_21=[y21 y22 y23 y24];
Derivada_2=mean(Derivada_21) %valor de la segunda derivada

%Se tomo en cuenta el promedio de las diferentes derivadas obtenidas entre


%los diferentes puntos ya que se puede interpretar este ejemplo como una
%funcion lineal como se muestra en la grafica. caso contrario se obtendria
%como resultado un conjunto de valores
EULER
%alex quinga
%EULER
% 08/06/2019
%Ecuacion diferencial
%Este programa permite aproximar el valor de la ecuacion diferencial con la
%ayuda de un ciclo for con el metodo de Euler
% Valores de verificacion
xa= 0:0.005:1;
ya=-xa.^2-2*xa+exp(xa)-2;%Ecaucion real para verificacion
plot(xa,ya)
hold on
h=0.1;
x1=0:h:1;% valores de x
Y1=zeros(1,length(x1));%Matriz de conserva
k=1;
y1=-1;
Y1(1)= y1;
for x=0:h:1
y1=y1+(x^2+y1)*h;
k=k+1;
Y1(k)=y1;
end
plot(x1,Y1(1:end-1))
HEUN
% Alex Quinga
%06/23/2019
% heun
%halla la respuesta por medio del promedio de dos pendientes cada promedio
aproxima mejor la respuesta
m=0:0.1:1;
n=-m.^2-2*m+exp(m)-2;
plot (m,n)
hold on
%
%
x0=0;
y0=-1;
h=0.1;
yi=y0;
xi=x0;
for i=1:10
y=yi+(x0^2+yi)*h;
p1=xi^2+yi;
xi=xi+h;
p2=xi^2+y;
pp=(p1+p2)/2;
yi=yi+pp*h;
X(i)=xi;
Y(i)=yi;
end
plot(X,Y)
INTERPOLACION POR EL METODO DE NEWTON

% Alex Quinga
%06/06/2019
% Interpolacion por el metodo de Newton
clear
clc
% Con este valor se desea calcular el valor de f(1.5)
%%%primera diferencia dividida
format short
xz= 0:0.05:10;
yz= sin(xz);
plot(xz,yz,'r'); hold on
%
a=1.5;
x=1:0.9:10;
y=sin(x);
plot(x,y,'ob')
%primeras diferencias divididas
y11=(y(1)-y(2))/(x(1)-x(2));%f(x0,x1)
y12=(y(2)-y(3))/(x(2)-x(3));%f(x1,x2)
y13=(y(3)-y(4))/(x(3)-x(4));%f(x2,x3)
y14=(y(4)-y(5))/(x(4)-x(5));%f(x3,x4)
y15=(y(5)-y(6))/(x(5)-x(6));%f(x4,x5)
y16=(y(6)-y(7))/(x(6)-x(7));%f(x5,x6)
y17=(y(7)-y(8))/(x(7)-x(8));%f(x7,x8)
y18=(y(8)-y(9))/(x(8)-x(9));%f(x8,x9)
y19=(y(9)-y(10))/(x(9)-x(10));%f(x9,x10)
y110=(y(10)-y(11))/(x(10)-x(11));%f(x10,x11)
%segundas diferencias divididas
y21=(y11-y12)/(x(1)-x(3));%f(x0,x1,x2)
y22=(y12-y13)/(x(2)-x(4));%f(x1,x2,x3)
y23=(y13-y14)/(x(3)-x(5));%f(x2,x3,x4)
y24=(y14-y15)/(x(4)-x(6));%f(x3,x4,x5)
y25=(y15-y16)/(x(5)-x(7));%f(x4,x5,x6)
y26=(y16-y17)/(x(6)-x(8));%f(x5,x6,x7)
y27=(y17-y18)/(x(7)-x(9));%f(x6,x7,x8)
y28=(y18-y19)/(x(8)-x(10));%f(x7,x8,x9)
y29=(y19-y110)/(x(9)-x(11));%f(x8,x9,x10)
%terceras diferencias divididas
y31=(y21-y22)/(x(1)-x(4));%f(x0,x1,x2,x3)
y32=(y22-y23)/(x(2)-x(5));%f(x1,x2,x3,x4)
y33=(y23-y24)/(x(3)-x(6));%f(x2,x3,x4,x5)
y34=(y24-y25)/(x(4)-x(7));%f(x3,x4,x5,x6)
y35=(y25-y26)/(x(5)-x(8));%f(x4,x5,x6,x7)
y36=(y26-y27)/(x(6)-x(9));%f(x5,x6,x7,x8)
y37=(y27-y28)/(x(7)-x(10));%f(x6,x7,x8,x9)
y38=(y28-y29)/(x(8)-x(11));%f(x7,x8,x9,x10)
%Interpolacion -metodo de Newton y error
%Primera Aproximacion
yt1=y(1)+(a-x(1))*y11;
error1=abs((yt1-sin(a))/sin(a))*100;
%Segunda Aproximacion
yt2=y(1)+(a-x(1))*y11+(a-x(1))*(a-x(2))*y21;
error2=abs((yt2-sin(a))/sin(a))*100;
%Tercera Aproximacion
yt3=y(1)+(a-x(1))*y11+(a-x(1))*(a-x(2))*y21+(a-x(1))*(a-x(2))*(a-x(3))*y31;
error3=abs((yt2-sin(a))/sin(a))*100;
Sol_N=[yt1 yt2 yt3;error1 error2 error3]
%Interpolacion metodo de Lagrange y error

INTERPOLACION POR LAGRANGE

%Alex Quinga
%06/06/2019
% Interpolacion por el metodo de Newton
clear
clc
% Con este valor se desea calcular el valor de f(1.5)
%%%primera diferencia dividida
format short
xz= 0:0.05:10;
yz= sin(xz);
plot(xz,yz,'r'); hold on
%
a=1.5;
x=1:0.9:10;
y=sin(x);
plot(x,y,'ob')
%calculo de los polinomios de Lagrange
L1=((a-x(2))*(a-x(3))*(a-x(4))*(a-x(5))*(a-x(6))*(a-x(7))*(a-x(8))*(a-
x(9))*(a-x(10))*(a-x(11)))/((x(1)-x(2))*(x(1)-x(3))*(x(1)-x(4))*(x(1)-
x(5))*(x(1)-x(6))*(x(1)-x(7))*(x(1)-x(8))*(x(1)-x(9))*(x(1)-x(10))*(x(1)-
x(11)));
L2=((a-x(1))*(a-x(3))*(a-x(4))*(a-x(5))*(a-x(6))*(a-x(7))*(a-x(8))*(a-
x(9))*(a-x(10))*(a-x(11)))/((x(2)-x(1))*(x(2)-x(3))*(x(2)-x(4))*(x(2)-
x(5))*(x(2)-x(6))*(x(2)-x(7))*(x(2)-x(8))*(x(2)-x(9))*(x(2)-x(10))*(x(2)-
x(11)));
L3=((a-x(1))*(a-x(2))*(a-x(4))*(a-x(5))*(a-x(6))*(a-x(7))*(a-x(8))*(a-
x(9))*(a-x(10))*(a-x(11)))/((x(3)-x(1))*(x(3)-x(2))*(x(3)-x(4))*(x(3)-
x(5))*(x(3)-x(6))*(x(3)-x(7))*(x(3)-x(8))*(x(3)-x(9))*(x(3)-x(10))*(x(3)-
x(11)));
L4=((a-x(1))*(a-x(2))*(a-x(3))*(a-x(5))*(a-x(6))*(a-x(7))*(a-x(8))*(a-
x(9))*(a-x(10))*(a-x(11)))/((x(4)-x(1))*(x(4)-x(2))*(x(4)-x(3))*(x(4)-
x(5))*(x(4)-x(6))*(x(4)-x(7))*(x(4)-x(8))*(x(4)-x(9))*(x(4)-x(10))*(x(4)-
x(11)));
L5=((a-x(1))*(a-x(2))*(a-x(3))*(a-x(4))*(a-x(6))*(a-x(7))*(a-x(8))*(a-
x(9))*(a-x(10))*(a-x(11)))/((x(5)-x(1))*(x(5)-x(2))*(x(5)-x(3))*(x(5)-
x(4))*(x(5)-x(6))*(x(5)-x(7))*(x(5)-x(8))*(x(5)-x(9))*(x(5)-x(10))*(x(5)-
x(11)));
yfinal1=y(1)*L1+y(2)*L2+y(3)*L3+y(4)*L4+y(5)*L5
RUNGE KUTA

%Quinga Alex
% 17/06/2019
%Ecuacion diferencial: x^2+y
%Este programa permite aproximar el valor de la ecuacion diferencial con la
%ayuda de un ciclo for con el metodo de Runge- Kutta .
%
%Condiciones y parametros iniciales
x0=0; % Valor inicial de x
y0=-1; % Valor inicial de y
h=0.1; % Delta x
yi_1=y0; % Acumulador
for i=1:10
xi=x0+h*i; %
k1=xi^2+yi_1;
k2=(xi+0.5*h)^2+(yi_1+0.5*k1*h);
k3=(xi+0.5*h)^2+(yi_1+0.5*k2*h);
k4=(xi+h)^2+(yi_1+k3*h);
phi= 1/6*(k1+2*k2+2*k3+k4);
yi_1= yi_1+phi*h;
X(i)=xi;
Y(i)=yi_1;
end
X
Y
plot (X,Y)
hold on
%
%
m=0:0.1:1;
n=-m.^2-2*m+exp(m)-2;
plot (m,n)
hold on

Das könnte Ihnen auch gefallen