You are on page 1of 2

%daniel

%promedio de cada tres elementos


clear all
clc
A=[30 20 56 5 8
4 10 12 6 2
15 12 11 10 9];
a=input('ingrese una matriz a=' )
[f,c]=size(A);
for i=1:1:3
B(1,i)=sum(A(1,i:i+2))/3;
end
%A(1,1:3)/3
%A(1,2:4)/3
%A(1,3:5)/3
for j=1:f
for i=1:c-2
B(j,i)=sum(A(2,i:i+2))/3
end
end
%A(2,1:3)/3
%A(2,2:4)/3
%A(2,3:5)/3
%for i=1:1:3
% B(3,i)=sum(A(3,i:i+2))/3
%end
%A(3,1:3)/3
%A(3,2:4)/3
%A(3,3:5)/3

Contar nmeros negativos de una matriz:


%daniel
clear all
clc
m=input('Ingrese la matriz m: ');
cont=0;
[f,c]=size(m);
for i=1:1:f
for j=1:1:c
if m(i,j)<0
cont=cont+1;
end
end
end
fprintf('El numero de elemetos negativos:
');
disp(cont);
ejecucin:
Ingrese la matriz m: [1 2 3 , -4 -5 -6]
el numero de elemetos negativos:
3

clear
clc
format rat
a=input('ingrese una matriz a=' );
b=input('ingrese el vector b=' );
x(0)=input('ingrese x(0)=' );
w=input('ingrese la variable w=' );
tol=input('ingrese la tolerancia=' );
[n,M]=size (a);
for i=1:1:n
x(i)=x(0i);
end
k=1;
while k<=N
S=0;
for j=1:1:i-1
S=S+(a(i,j)*x(j));
end
s=0;
for j=i+1:1:n
s=s+(a(i,j)*x(0i)(j));
for i=1:1:n
x(i)=(1-w)*x(oi)+w*((-S-s+b(i))/a(i,i));
end
end
if norm(x-x(0),inf)<tol
disp(x);
return;
else k=k+1
for i=1:1:n
x(0i)=x(i);
end
end
end

You might also like