Версия для печати темы

Нажмите сюда для просмотра этой темы в обычном формате

Форум «Всё о Паскале» _ Задачи _ Немогу понять какие матрицы нужны программе!

Автор: metamfetamin 24.11.2007 18:13

Есть программа.....немогу сообразить какие матрицы с какими елементами (как именно их описать в блокноте) нужны етой программе что б она их открыла и зделала соответствующие пробразования?????

program umblok;
uses crt;
type mas=array[1..7,1..7] of integer;
var
m,n,k,i,j,p,s,r,l,l1,kk,w,g,t,SA11,SA12,SA21,SA22,SB11,SB12,SB21,SB22:integer;
a,b,c,d:mas;
A11,A12,A21,A22,B11,B12,B21,B22:mas;
z1,z2:boolean;
c01,c02,c03,c04,c05,c06,c07,c08:mas;
c11,c12,c21,c22:mas;
t1:text;
name1:string;

procedure vvod;
var tv:text;
name:string;
begin
writeln('vvedi imya faila');
readln(name);
assign(tv,name);
reset(tv);
for i:=1 to m do
begin
for j:=1 to n do
read(tv,a[i,j]);
readln(tv);
end;
readln(tv);
for i:=1 to n do
begin
for j:=1 to k do
read(tv,b[i,j]);
readln(tv);
end;
close(tv);
end;

procedure viv(d:mas;kstrd,kstd:integer);
begin
for i:=1 to kstrd do
begin
for j:=1 to kstd do
write(t1,d[i,j],' ');
writeln(t1);
end;
writeln(t1);
end;

procedure umnog(X,Y:mas;mx,kx,nx:integer;var Z:mas);
begin
for i:=1 to mx do
for j:=1 to kx do
begin
s:=0;
for p:=1 to nx do
s:=s+X[i,p]*Y[p,j];
z[i,j]:=s;
end;
end;

procedure viv_c;
var t:text;
name:string;
begin
writeln('vvedi imya faila ');
readln(name);
assign(t,name);
append(t);
writeln(t,' matrica c:');
writeln(t);
for i:=1 to m do
begin
for j:=1 to k do
write(t,c[i,j]:4);
writeln(t);
end;
close(t);
end;

procedure razbien(aa:mas;i1,i2,j1,j2,k,l:integer;var d:mas);
begin
for i:=i1 to i2 do
for j:=j1 to j2 do
d[i-k,j-l]:=aa[i,j];
end;

procedure vivnaek(x:mas;n1,m1:integer);
begin
for i:=1 to n1 do
begin
for j:=1 to m1 do
write(x[i,j]:4);
writeln;
end;
end;

procedure nulmatr(x:mas;n1,m1:integer; var s:integer);
begin
s:=0;
for i:=1 to n1 do
for j:=1 to m1 do
s:=s+x[i,j];
end;

begin
m:=6;
n:=7;
k:=6;
clrscr;
writeln('vvod el-tov matr.A i B:');

vvod;

writeln(' matrica a:');
for i:=1 to m do
begin
for j:=1 to n do
write(' ',a[i,j]);
writeln;
end;

writeln(' matrica b:');
for i:=1 to n do
begin
for j:=1 to k do
write(' ',b[i,j]); writeln;
end;

for i:=1 to m do
for j:=1 to k do
c[i,j]:=0;
readln;

razbien(a,1,2,1,4,0,0,A11);
writeln('matrica A11');
vivnaek(A11,2,4);
razbien(a,1,2,5,7,0,4,A12);
writeln('matrica A12');
vivnaek(A12,2,3);
razbien(a,3,6,1,4,2,0,A21);
writeln('matrica A21');
vivnaek(A21,4,4);
razbien(a,3,6,5,7,2,4,A22);
writeln('matrica A22');
vivnaek(A22,4,3);
readln;
razbien(b,1,4,1,3,0,0,B11);
writeln('matrica B11');
vivnaek(B11,4,3);
razbien(b,1,4,4,6,0,3,B12);
writeln('matrica B12');
vivnaek(B12,4,3);
razbien(b,5,7,1,3,4,0,B21);
writeln('matrica B21');
vivnaek(B21,3,3);
razbien(b,5,7,4,6,4,3,B22);
writeln('matrica B22');
vivnaek(B22,3,3);
readln;

nulmatr(A11,2,4,SA11);
writeln('SA11=',SA11:3);
nulmatr(A12,2,3,SA12);
writeln('SA12=',SA12:3);
nulmatr(A21,4,4,SA21);
writeln('SA21=',SA21:3);
nulmatr(A22,4,3,SA22);
writeln('SA22=',SA22:3);
nulmatr(B11,4,3,SB11);
writeln('SB11=',SB11:3);
nulmatr(B12,4,3,SB12);
writeln('SB12=',SB12:3);
nulmatr(B21,3,3,SB21);
writeln('SB21=',SB21:3);
nulmatr(B22,3,3,SB22);
writeln('SB22=',SB22:3);

z1:=false; z2:=false;
if (SA11<>0) and (SB11<>0) then
begin
umnog(A11,B11,2,3,4,c01);
z1:=true;
end;
if (SA12<>0) and (SB21<>0) then
begin
umnog(A12,B21,2,3,3,c02);
z2:=true;
end;
if (z1=true) and (z2=true) then
begin
for i:=1 to 2 do
for j:=1 to 3 do
c11[i,j]:=c01[i,j]+c02[i,j];
end;
if (z1=true) and (z2=false) then
begin
for i:=1 to 2 do
for j:=1 to 3 do
c11[i,j]:=c01[i,j];
end;
if (z1=false) and (z2=true) then
begin
for i:=1 to 2 do
for j:=1 to 3 do
c11[i,j]:=c02[i,j];
end;
writeln('matrica c11');
vivnaek(c11,2,3);

z1:=false; z2:=false;
if (SA11<>0) and (SB12<>0) then
begin
umnog(A11,B12,2,3,4,c03);
z1:=true;
end;
if (SA12<>0) and (SB22<>0) then
begin
umnog(A12,B22,2,3,3,c04);
z2:=true;
end;
if (z1=true) and (z2=true) then
begin
for i:=1 to 2 do
for j:=1 to 3 do
c12[i,j]:=c03[i,j]+c04[i,j];
end;
if (z1=true) and (z2=false) then
begin
for i:=1 to 2 do
for j:=1 to 3 do
c12[i,j]:=c03[i,j]
end;
if (z1=false) and (z2=true) then
begin
for i:=1 to 2 do
for j:=1 to 3 do
c12[i,j]:=c04[i,j];
end;
writeln('matrica c12');
vivnaek(c12,2,3);

z1:=false; z2:=false;
if (SA21<>0) and (SB11<>0) then
begin
umnog(A21,B11,4,3,4,c05);
z1:=true;
end;
if (SA22<>0) and (SB21<>0) then
begin
umnog(A22,B21,4,3,3,c06);
z2:=true;
end;
if (z1=true) and (z2=true) then
begin
for i:=1 to 4 do
for j:=1 to 3 do
c21[i,j]:=c05[i,j]+c06[i,j];
end;
if (z1=true) and (z2=false) then
begin
for i:=1 to 4 do
for j:=1 to 3 do
c21[i,j]:=c05[i,j]
end;
if (z1=false) and (z2=true) then
begin
for i:=1 to 4 do
for j:=1 to 3 do
c21[i,j]:=c06[i,j];
end;
writeln('matrica c21');
vivnaek(c21,4,3);

z1:=false; z2:=false;
if (SA21<>0) and (SB12<>0) then
begin
umnog(A21,B12,4,3,4,c07);
z1:=true;
end;
if (SA22<>0) and (SB22<>0) then
begin
umnog(A22,B22,4,3,3,c08);
z2:=true;
end;
if (z1=true) and (z2=true) then
begin
for i:=1 to 4 do
for j:=1 to 3 do
c22[i,j]:=c07[i,j]+c08[i,j];
end;
if (z1=true) and (z2=false) then
begin
for i:=1 to 4 do
for j:=1 to 3 do
c22[i,j]:=c07[i,j];
end;
if (z1=false) and (z2=true) then
begin
for i:=1 to 4 do
for j:=1 to 3 do
c22[i,j]:=c08[i,j];
end;
writeln('matrica c22');
vivnaek(c22,4,3);

for i:=1 to 2 do
for j:=1 to 3 do
begin
c[i,j]:=c11[i,j];
c[i,j+3]:=c12[i,j];
end;
for i:=1 to 4 do
for j:=1 to 3 do
begin
c[i+2,j]:=c21[i,j];
c[i+2,j+3]:=c22[i,j];
end;
readln;
writeln('matrica c');
vivnaek(c,6,6);
writeln('vvedi imya faila rezult');
readln(name1);
assign(t1,name1);
rewrite(t1);
writeln('rezult');
writeln(t1,'matrica C11');
viv(C11,2,3);
writeln(t1,'matrica C12');
viv(C12,2,3);
writeln(t1,'matrica C21');
viv(C21,4,3);
writeln(t1,'matrica C22');
viv(C22,4,3);
close(t1);
viv_c;
readln;
end.
Какого вида елементы использывать в етой матрице???Есть несколько вариантов!!!!!
1) 0.1, 0,2 и т.д.(десятичные)
2) 1 2 4 и т.д. (целые).
Или как то иначе!!!Помогите !!!!Если нужны матрицы - скажите я выложу!!!!

Автор: volvo 24.11.2007 21:23

Вообще-то, матрицы A и B, которые и вводятся из файла, описаны как

type mas=array[1..7,1..7] of integer;
, значит - целочисленные...

Автор: metamfetamin 24.11.2007 21:32

Цитата(volvo @ 24.11.2007 17:23) *
Вообще-то, матрицы A и B, которые и вводятся из файла, описаны как
type mas=array[1..7,1..7] of integer;
, значит - целочисленные...
VOLVO такие матрицы подойдут???
A
2 3 0 0 0 0
4 0 5 7 0 0
0 2 0 3 9 0
0 0 7 0 1 0
0 0 0 4 0 6



B
5 3 0 0 0 0 0	
8 0 2 4 0 0 0
0 6 0 9 7 0 0
0 0 7 0 8 0 0
0 0 0 4 0 5 0
0 0 0 0 0 0 6



Если да, то не подскажеш почему при вводе имени файла, так как требуется при запуске программы мне выдает ошибку file not found в следующей части программы (reset(tv);)!!!!
procedure vvod;
var tv:text;
name:string;
begin
writeln('vvedi imya faila');
readln(name);
assign(tv,name);
reset(tv);
for i:=1 to m do
begin
for j:=1 to n do
read(tv,a[i,j]);
readln(tv);
end;
readln(tv);
for i:=1 to n do
begin
for j:=1 to k do
read(tv,b[i,j]);
readln(tv);
end;
close(tv);
end;

Автор: volvo 24.11.2007 21:56

Цитата
почему при вводе имени файла, так как требуется при запуске программы мне выдает ошибку file not found
Не знаю... Только что запустил программу с твоими данными, никакой ошибки не получил...

Автор: metamfetamin 24.11.2007 22:14

Цитата(volvo @ 24.11.2007 17:56) *

Не знаю... Только что запустил программу с твоими данными, никакой ошибки не получил...

У меня тоже запустилось!!!!! Если что будет не понятно спрошу!!!!Спасибо огромное за помощь!!!!!


Эскизы прикрепленных изображений
Прикрепленное изображение

Автор: metamfetamin 25.11.2007 1:41

Цитата(volvo @ 24.11.2007 17:56) *

Не знаю... Только что запустил программу с твоими данными, никакой ошибки не получил...


немогу понять что в данной программе обозначают строки выделеные цветом.и каким образом ети цыфры влияют на перемещение елементов в матрице в зависимости от их меняется елемент в строке(столбце)!!!!
razbien(a,1,2,1,4,0,0,A11);
writeln('matrica A11');
vivnaek(A11,2,4);
razbien(a,1,2,5,7,0,4,A12);
writeln('matrica A12');
vivnaek(A12,2,3);
razbien(a,3,6,1,4,2,0,A21);
writeln('matrica A21');
vivnaek(A21,4,4);
razbien(a,3,6,5,7,2,4,A22);
writeln('matrica A22');
vivnaek(A22,4,3);
readln;
razbien(b,1,4,1,3,0,0,B11);
writeln('matrica B11');
vivnaek(B11,4,3);
razbien(b,1,4,4,6,0,3,B12);
writeln('matrica B12');
vivnaek(B12,4,3);
razbien(b,5,7,1,3,4,0,B21);
writeln('matrica B21');
vivnaek(B21,3,3);
razbien(b,5,7,4,6,4,3,B22);
writeln('matrica B22');
vivnaek(B22,3,3);
readln;