You are on page 1of 4

%eliminacion de gauss

clc
A=[4 -9 2 5; 2 -4 6 3; 1 -1 3 4]
A(2,:)=A(2,:)-A(1,:)*A(2,1)/A(1,1);
A(3,:)=A(3,:)-A(1,:)*A(3,1)/A(1,1);
A
A(3,:)=A(3,:)-A(2,:)*A(3,2)/A(2,2);
x(3)=A(3,4)/A(3,3);
x(2)=(A(2,4)-A(2,3)*x(3))/A(2,2);
x(1)=(A(1,4)-A(1,2:3)*x(2:3))/A(1,1)

%eliminacion de gauss con pivoteo


clc
A=[2 -4 6 3; 4 -9 2 5; 1 -1 3 4]
copia=A(2,:);
A(2,:)=A(1,:);
A(1,:)=copia;
A(2,:)=A(2,:)-A(1,:)*A(2,1)/A(1,1);
A(3,:)=A(3,:)-A(1,:)*A(3,1)/A(1,1);
A
A(3,:)=A(3,:)-A(2,:)*A(3,2)/A(2,2);
A
x(3)=A(3,4)/A(3,3);
x(2)=(A(2,4)-A(2,3)*x(3))/A(2,2);
x(1)=(A(1,4)-A(1,2:3)*x(2:3))/A(1,1);
x
clc
clear memory
%resolvemos la ecuacion
disp('METODOS NUMERICOS')
syms x y
disp('-------------------------METODO NEWTHON
RAPSHON--------------------')
f1=log(0.25+x*0.75)+0.75*(((x)/(0.25+x*0.75))-((y)/(0.75+y*0.25)))log(1.12);
f2=log(0.75+y*0.25)-0.25*(((x)/(0.25+x*0.75))-((y)/(0.75+y*0.25)))log(1.6);
f1x=diff(f1,x);
f1y=diff(f1,y);
f2x=diff(f2,x);
f2y=diff(f2,y);
x=0;
y=0;
Eps=1e-5;
fprintf(' n
x(n)
y(n)
Dist\n ')
fprintf(' %2d
%10.4
%10.4f\n',0,x,y)
for n=1:13
%componentes de la matriz jacobiana
vf1=eval(f1);
vf2=eval(f2);
vf1x=eval(f1x);
vf1y=eval(f1y);
vf2x=eval(f2x);
vf2y=eval(f2y);

j=[vf1x vf1y ;vf2x vf2y];


b=[-vf1;-vf2];%solucion de la matriz jacobiana
rx=inv(j)*b;
h=rx(1);
j=rx(2);
%soluciones
x1=x+h;
y1=y+j;
dist=((x1-x)^2+(y1-y)^2)^0.5;
fprintf(' %2d %10.5f
%10.5f
%10.5f\n',n,x1,y1,dist)
if dist<Eps
break
end
x=x1;
y=y1;
end
disp('....................................................')

%Programa de Factorizacin L U para un SEL


clc
clear
disp(' ')
disp(' Resolucin de un SEL con la Factorizacin Doolitle ')
disp(' ************************************************** ')
disp(' ')
c=0;
d=0;
N=input(' Ingrese el nmero de ecuaciones: ');
A=input(' Ingrese la matriz de coeficientes A: ');
disp(' ')
disp([A])
b=input(' Ingrese la matriz de trminos independientes b: ');
disp(' ')
disp([b])
L=zeros(size(A));
U=zeros(size(A));
while c==0
d=d+1;
L(d,d)=1;
U(1,d)=A(1,d);
if d<N
L(d+1,1)=A(d+1,1)/U(1,1);
c=0;
else
c=1;
end
end
for i=2:N;
for j=2:N;
J=0;
H=0;
for k=1:i-1;
J=J+L(i,k)*U(k,j);
end

U(i,j)=A(i,j)-J;
if i==j
L(j,i)=1;
else
for k=1:i-1;
H=H+U(k,i)*L(j,k);
end
if i<j
L(j,i)=(1/U(i,i))*(A(j,i)-H);
end
end
end
end
fprintf(' La matriz triangular inferior es L:\n');
disp(' ')
disp([L])
fprintf(' La matriz triangular superior es U:\n');
disp(' ')
disp([U])

%Programa de Factorizacin L U para un SEL


clc
clear
disp(' ')
disp(' Resolucin de un SEL con la Factorizacin Doolitle ')
disp(' ************************************************** ')
disp(' ')
c=0;
d=0;
N=input(' Ingrese el nmero de ecuaciones: ');
A=input(' Ingrese la matriz de coeficientes A: ');
disp(' ')
disp([A])
b=input(' Ingrese la matriz de trminos independientes b: ');
disp(' ')
disp([b])
L=zeros(size(A));
U=zeros(size(A));
while c==0
d=d+1;
L(d,d)=1;
U(1,d)=A(1,d);
if d<N
L(d+1,1)=A(d+1,1)/U(1,1);
c=0;
else
c=1;
end
end
for i=2:N;
for j=2:N;
J=0;
H=0;
for k=1:i-1;

J=J+L(i,k)*U(k,j);
end
U(i,j)=A(i,j)-J;
if i==j
L(j,i)=1;
else
for k=1:i-1;
H=H+U(k,i)*L(j,k);
end
if i<j
L(j,i)=(1/U(i,i))*(A(j,i)-H);
end
end
end
end
fprintf(' La matriz triangular inferior es L:\n');
disp(' ')
disp([L])
fprintf(' La matriz triangular superior es U:\n');
disp(' ')
disp([U])

%interpolacion por el metodo lagrange


clear memory
clc
x=input('ingrese dato a interpolar: ');
x0=900;
x1=1000;
x2=2000;
x3=3000;
f0=0.0045;
f1=0.006;
f2=0.003;
f3=0.004;
l0=(x-x1)/(x0-x1)*(x-x2)/(x0-x2)*(x-x3)/(x0-x3);
l1=(x-x0)/(x1-x0)*(x-x2)/(x1-x2)*(x-x3)/(x1-x3);
l2=(x-x0)/(x2-x0)*(x-x1)/(x2-x1)*(x-x3)/(x2-x3);
l3=(x-x0)/(x3-x0)*(x-x1)/(x3-x1)*(x-x2)/(x3-x2);
disp 'para el valor ingresado f vale: '
f=l0*f0+l1*f1+l2*f2+l3*f3

You might also like