You are on page 1of 6

Metodo de la inversa de la Matriz con Gauss-Jordan en

Matlab
clear all;
clc;
fprintf('Dame la matriz a la que le quieres
f=input('cuantas filas:');
c=input('cuantas columnas:');
for k=1:c
for j=1:f
fprintf('fila: %x\n',j)
fprintf('columna: %x',k)
r=input('numero de esta fila y columna:
a(j,k)=r;
j=j+1;
end
k=k+1;
end
a
b=a;
pause
fprintf('dame la matriz identidad del mismo
anterio\n\n')
for k=k:c*2
for j=1:f
fprintf('fila: %x\n',j)
fprintf('columna: %x',k)
r=input('numero de esta fila y columna:
a(j,k)=r;
j=j+1;
end
k=k+1;
end
a
pause
for k=1:c
a(k,:)=a(k,:)/a(k,k);
for j=k+1:f
a(j,:)=a(j,:)-a(k,:)*a(j,k);
j=j+1;
a
pause
end
k=k+1;
a
pause
end
for k=f:-1:2
for j=k-1:-1:1
a(j,:)=a(j,:)-a(k,:)*a(j,k);
j=j-1;
a
pause
end
k=k-1;
a

calcular la inversa: \n')

');

grado que la matriz

');

pause
end
fprintf('calculo la inversa para comprobar directo con matlab\n')
c=inv(b);
c

Integrales definidas e Indefinidas en Matlab


>> %Integrales en Matlab
>> %Integral indefinida
>> syms
>> syms x
>> f= 2*x^4;
>> F = int(f)
F =
(2*x^5)/5
>> %integral definida
>> F = int(f,3,2)
F =
-422/5
>> %integrales impropias (al infinito)
>> D = (exp(-x)*sin(x))/x
D =
(exp(-x)*sin(x))/x
>> pretty (D)
exp(-x) sin(x)
-------------x
>> DD =int(D,0,inf)
DD =
pi/4
>> DD =int(D)
DD =

(ei(x*(- 1 - i))*i)/2 - (ei(x*(- 1 + i))*i)/2


>> pretty(DD)
ei(x (- 1 - i)) i
ei(x (- 1 + i)) i
----------------- - ----------------2
2
>>

Derivadas en Matlab.
Seguimos con las publicaciones de Matlab para calculo, ahora toca el tema de derivadas.
>> syms x
>> f = 2*x^2;
>> %procedemos a derivarla mendiante el comando diff()
>> diff(f)
ans =
4*x
>>
>>
>>
>>

%% DERIVADA PARCIAL
syms y
F= 2*x^3*y;
diff(F,x)% con respecto a X

ans =
6*x^2*y
>> diff(F,y)% con respecto a Y
ans =
2*x^3
>>
>>
>>
>>

% las letras que son consideras literales son: x,w,y,z


%todas las demas letras son consideradas constantes
syms a
f2 = 3*a*x^2

f2 =
3*a*x^2
>> diff(f2)
ans =
6*a*x
>> syms x n
>> f3 = x^n;

>> diff (f3)


ans =
n*x^(n - 1)
>> f3 = sqrt(x^n);
>> F2 = diff(f3)
F2 =
(n*x^(n - 1))/(2*(x^n)^(1/2))
>> % si nos damos cuenta tenemos
derivacion
>> pretty(F2)

en estos 2 utimos casos las formulas de

n - 1
n x
--------n 1/2
2 (x )
>> ans
ans =
n*x^(n - 1)
>> pretty (ans)
n - 1

n x

Cdigo Matlab Mtodo de Newton-Raphson


26 comentariosPublicado por BeAsTiEuX en octubre 25, 2008

x0=input('Ingrese el valor inicial: ');


tol=input('Ingrese el porcentaje de error: ');

f=input('Ingrese la funcin: ');


i=1;
fx(i)=x0;

syms x;
f1=subs(f,x,fx(i));
z=diff(f);
d=subs(z,x,fx(i));

ea(1)=100;

while abs(ea(i))>=tol;
fx(i+1)=fx(i)-f1/d; f1=subs(f,x,fx(i+1)); d=subs(z,x,fx(i+1));
ea(i+1)=abs((fx(i+1)-fx(i))/fx(i+1)*100);
i=i+1;
end
fprintf('i

fx(i)

Error aprox (i) \n');

for j=1:i;
fprintf('%2d \t %11.7f \t %7.3f \n',j-1,fx(j),ea(j));
end
x0=input('Ingrese el valor inicial: ');
tol=input('Ingrese el porcentaje de error: ');
f=input('Ingrese la funcin: ');
i=1;
fx(i)=x0;
syms x;
f1=subs(f,x,fx(i));
z=diff(f);
d=subs(z,x,fx(i));
ea(1)=100;
while abs(ea(i))>=tol;
fx(i+1)=fx(i)-f1/d; f1=subs(f,x,fx(i+1)); d=subs(z,x,fx(i+1));
ea(i+1)=abs((fx(i+1)-fx(i))/fx(i+1)*100);
i=i+1;
end
fprintf('i
fx(i)
Error aprox (i) \n');

for j=1:i;
fprintf('%2d \t %11.7f \t %7.3f \n',j-1,fx(j),ea(j));
end

You might also like