Matlab - como programo una suma y resta de matrices

 
Vista:

como programo una suma y resta de matrices

Publicado por ffeo (8 intervenciones) el 11/12/2014 22:15:05
no se como se hace?????'
y que es lo que me falla???
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
clc
clear all
f1=input('Dame el numero de renglones de la primera matris: ');
c1=input('Dame el numero de Columnas de la primera matris: ');
for i=1:f1
    for j=1:c1
        fprintf('Valor (%d,%d):',i,j);
        m(i,j)=input('');
    end
end
fprintf('La primera matriz es:\n\n');
 
for i=1:f1
    for j=1:c1
        fprintf('%d\t',m(i,j));
    end
    fprintf('\n');
end
f2=input('Dame el numero de Filas de la segunda matriz : ');
c2=input('Dame el numero de Columnas de la segunda matriz : ');
for i=1:f2
    for j=1:c2
        fprintf('Valor (%d,%d):',i,j);
        m2(i,j)=input('');
    end
end
fprintf('La Segunda matriz es:\n\n');
 
for i=1:f2
    for j=1:c2
        fprintf('%d\t',m2(i,j));
    end
    fprintf('\n');
end
o=input('Que deceas hacer:\n1).-Suma\n2).-Resta\n3).-Multiplicacion');
if o==1 || o==2
if f1==f2 && c1==c2
    if o==1
    for i=1:f1
        for j=1:c1
        sum1=0;
        sum1=sum1+m2(i,j)+m(i,j);
        m3(i,j)=sum1;
 
        end
    end
fprintf('La  matriz resultante es:\n\n');
    for i=1:f2
        for j=1:c2
        fprintf('%d\t',m3(i,j));
        end
    fprintf('\n');
    end
    end
    if o==2
     for i=1:f1
        for j=1:c1
        sum1=0;
        sum1=m2(i,j)-m(i,j);
        m3(i,j)=sum1;
 
        end
    end
fprintf('La  matriz resultante es:\n\n');
    for i=1:f2
        for j=1:c2
        fprintf('%d\t',m3(i,j));
        end
    fprintf('\n');
    end
    end
 
else
    fprintf('No se pueden sumar o restar las matrices');
end
else
     mul1=0;
     f3=0;
     c3=0;
    if c1==f2
        for i=1:f1
        f3=f3+1;
        for x=1:c2
        for j=1:c1
        mul1=(m(i,j)*m2(j,x))+mul1;
        end
        c3=c3+1;
        m3(f3,c3)=mul1;
        mul1=0;
        end
        c3=0;
        end
 
        fprintf('La  matriz resultante es:\n\n');
    for i=1:f1
        for j=1:c2
        fprintf('%d\t',m3(i,j));
        end
    fprintf('\n');
    end
 
 
    else
         fprintf('No se pueden multiplicar las matrices');
 
    end
end
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder