Вы находитесь на странице: 1из 10

UNIVERSIDAD POLITCNICA SALESIANA

TRABAJO FINAL
SEGUNDO PARCIAL
FACULTAD: INGENIERA ELCTRICA
MATERIA: METODOS NUMERICOS
ESTUDIANTE: JORGE EDUARDO QUISHPE FREIRE
FECHA DE ENTREGA: 11/02/2016

Realizar un scrip en Matlab con los diferentes mtodos numericos

Interpolacin de Newton

% % % INTERPOLACION DE NEWTON
% % % Los datos x0 = 1, x1 = 4 y x2 = 6
% % % se utilizaron para estimar ln 2 mediante una parbola.
% % % Ahora, agregando un cuarto punto (x3 = 5; f(x3) = 1.609438],
% % % estime ln 2 con un polinomio de interpolacin de Newton de
tercer grado.
clear;
clc;
n=input('INGRESAR EL GRADO DEL POLINOMIO n=');
fprintf('SE NECESITA %O.f PUNTOS\n',n+1);
disp('INGRESE LOS PUNTOS');
for j=1:n+1
fprintf('x%.0f=',j-1);
X(j)=input(' ');
fprintf('y%.0f=',j-1);
Y()=input(' ');
end
DD=zeros(n+1);
DD(:,1)=Y;
for m=2:n+1
for J=m:n+1
DD(J,m)=[DD(J,m-1)-DD(J-1,m-1)]/[X(J)-X(J-m+1)];
end
end
disp('LA MATRIZ DE DIFERENCIAS DIVIDIDAS ES:');
disp(DD);
disp('LA SOLUCION DEL POLINOMIO DE NEWTON ES');
syms x;
polnew=DD(1,1);
P=1;
for j=1:n
P=P*(x-X(j));
polnew=polnew+P*DD(j+1,j+1);
end
polnew=expand(polnew);
pretty(polnew);

x=input('INGRESAR EL VALOR DE x PARA INTERPOLAR, x=');


vi=eval(polnew);
fprintf('EL VALOR DE LA INTERPOLACION ES %.2f\n',vi);
hold on;
ezplot(polnew,[X(1) X(n+1)]);
plot(x,vi,'r+');

Interpolacin Cuadrtica

% % % INTERPOLACION CUADRATICA
% % % Ajuste un polinomio de segundo grado a los tres puntos
% % % del ejemplo 18.1:
% % % x0 = 1 f(x0) = 0
% % % x1 = 4 f(x1) = 1.386294
% % % x2 = 6 f(x2) = 1.791759
% % % Con el polinomio evale ln(2).
clear all, clc;
x=[1 4 6];
y=[0;1.38;1.79];
A=vander(x)
p=A\y
polyval(p,7)
xg=linspace(1,6);
yp=polyval(p,xg);
plot(x,y,'*',xg,yp)

Regresin Polinomial

% % % REGRESION POLINOMIAL
% % % Ajustar a un polinomio de segundo grado los datos dados
% % % en las dos primeras columnas de la tabla 17.4
% % % xi
yi
(yi y )2
(yi a0 a1xi a2xi 2)
% % % 0
2.1
544.44
0.14332
% % % 1
7.7
314.47
1.00286
% % % 2
13.6
140.03
1.08158
% % % 3
27.2
3.12
0.80491
% % % 4
40.9
239.22
0.61951
% % % 5
61.1
1272.11
0.09439
% % % ?
152.6
2513.39
3.74657
clear; format long
z=input('CUANTOS TERMINOS TIENE EL AJUSTE:')
for j=1:z
e(j)=input('INTRODUCIR VALOR EXPONENTE:')
end
x=[20,60,100,140,180,220,260,300,340,380]
y=[.18,.37,.35,.78,.56,.75,1.18,1.36,1.17,1.65]
n=10;
n=input('CUANTOS PUNTOS VA A AJUSTAS:')
disp('INTRODUCIR VALORES DE X')
for i =1:n
x(i)=input('INTRODUCE EL VALOR X:');
y(i)=input('INTRODUCE EL VALOR Y:');
end
for j=1:z
for i=1:n
A(i,j)=x(i)^e(j)
end
end
w=A\y'
plot(x,y,'*g')
hold on
xx=[min(x):3:max(x)];
for i=1:length (xx)
ytem(i)=0;
for k=1:z
yy(i)= w(k)*xx(i)^e(k)+ytem(i);
ytem(i)=yy(i);
end
end
plot(xx,ytem)
hold off
for i=1:length (x)
yte(i)=0;
for k=1:z
yy(i)= w(k)*x(i)^e(k)+yte(i);
yte(i)=yy(i);

end

end
yte=yte
E=(y-yte).^2
E2=sum(E)

Regresin Lineal por Mnimos Cuadrados.

% % % MINIMOS
% % % Utilice
lnea
% % % recta a
% % % calcule
corelacin

CUADRADOS
la regresin por mnimos cuadrados para ajustar una
los datos. Adems de la pendiente y la interseccin
el error estndar de la estimacin y el coeficiente de

clear;
clc;
xi=[0 2 4 6 9 11 12 15 17 19];
yi=[5 6 7 6 9 8 7 10 12 12];
disp('VALORES DE X');
disp(xi);
disp('VALORES DE Y');
disp(yi);
c=polyfit(xi,yi,1);
plot(xi,yi,'r*');
xp=linspace(1,20,20);
yp=polyval(c,xp);
hold on
grid on
plot(xp,yp);
disp('ECUACION ENCONTRADA');
disp(' PENDIENTE INTERSECCION');
disp(c);
disp('ERROR ESTANDAR');
fxi=polyval(c,xi);
error=sum((fxi-yi).^2);
disp(error);

disp('COEFICIENTE DE CORELACION');
n=length(xi);
errorcm=sqrt(sum((fxi-yi).^2)/n);
disp(errorcm);

Mtodo de Newton Raphson

% % % NEWTON-RAPHSON
% % % utilizando el mtodo de newton raphson resolver la ecuacin
% % % x^2+x+0.75 en el intervalo de (-3 , 6) y su valor inicial de 0
% % % realizando 6 iteraciones
Clc
close all
clear all
syms x
ffun=input('Ingrese la funcion f(x): ');
f=inline(ffun);
deriva=diff(ffun,x);
d=inline(deriva);
inf=input('Ingrese el limite inferior para graficar: ');

sup=input('Ingrese el limite superior para graficar: ');


t=linspace(inf,sup,100);
x=input('Ingrese el valor inicial: ');
in=input('Ingrese el numero de interaciones: ');
n=1; error=100; s=0;
fprintf('
n
\tx
\tf(x)
\td(x)
\terror\n')
disp([s,x,f(x),d(x)])
while (n<=in)
a=f(x);
b=d(x);
x1=x-(b-x/a);
error=abs(((x1-x)/x1)*100);
x=x1;
disp([n,x1,f(x1),d(x1),error])
n=n+1;
end
fprintf('La raiz estimada es de: %f\n',x1)
fprintf('Con un porcentaje de error aproximado de : %f\n',error)
fprintf('El numero de interaciones son: %f\n',n-1)
plot(t,subs(ffun,t));

Mtodo de la Secante.

% % % SECANTE
% % % Resolver el ejercicio mediante el mtodo de la secante de la
% % % funcin -12-21x+18X^2-2.4X^4 donde su intervalo es (0 , 1) y su
% % % porcentaje de error es de 1 %
clear, clc
cf= input('INGRESE LA FUNCION: ');
syms x
f= inline(cf);
derivada= diff(cf,x);
df= inline(derivada);
tol= input('INGRESE LA TOLERANCIA: ');
error= 50;
x= input('INGRESE EL VALOR INICIAL: ');
n=0;
disp(' n
xi
error')
while (error>tol)
fprintf('\t%i\t%3.5f\t%f\n', n, x, error);
n=n+1;
x= x - f(x)/df(x);
error= abs( f(x) );
end

Вам также может понравиться