SaveText.Ru

Без имени
  1. program matrica;
  2. uses crt;
  3. label r,p;
  4. var a,c: array [1..3, 1..3] of integer;
  5. b,d: array [1..3, 1..3] of real;
  6. i,j,s,k,y:integer;
  7. l,x,d1,d2,d3,x1,x2,x3:real;
  8. begin
  9. p:
  10. TextBackground(1);
  11. clrscr;
  12. textcolor(3);
  13. gotoxy(1,1); writeln('-------'); gotoxy(1,2); writeln(' 1 1 3 8');
  14. gotoxy(1,3); writeln(' A=-2 4 2, b=4'); gotoxy(1,4); writeln(' 3 7 1 24');
  15. gotoxy(1,5); writeln('-------'); writeln('1-Вычислить выражение (A*A)*B');
  16. writeln('2-Транспонировать матрицу А'); writeln('3 -Вычислить определитель матрицы А');
  17. writeln('4-Найти матрицу, обратную к матрице А'); writeln('5 -Решение системы методом Крамера');
  18. writeln('6-Выход'); writeln('Выберите нужную цифру'); readln(y);
  19. a[1,1]:=1; a[1,2]:=1; a[1,3]:=3; a[2,1]:=-2; a[2,2]:=4; a[2,3]:=2; a[3,1]:=3; a[3,2]:=7; a[3,3]:=1;
  20. if y=1 then begin
  21. for i:=1 to 3 do begin
  22. for j:=1 to 3 do begin
  23. s:=0;
  24. for k:=1 to 3 do begin
  25. s:=s+a[i,k]*a[k,j];
  26. end;
  27. c[i,j]:=s;
  28. end; end;
  29. for i:=1 to 3 do begin
  30. d[1]:=(c[1,1]*b[1])+(c[1,2]*b[2])+(c[1,3]*b[3]); d[2]:=(c[2,1]*b[1])+(c[2,2]*b[2])+(c[2,3]*b[3]);
  31. d[3]:=c[3,1]*b[1])+(c[3,2]*b[2])+c(c[3,3]*b[3]);
  32. end;
  33. textcolor(10: gotoxy(10,3); write('1. A=');
  34. for i:=1 to 3 do begin
  35. for j:=1 to 3 do begin
  36. gotoxy(12+4*i,1+j);
  37. writeln(a[i,j]);
  38. end; end;
  39. gotoxy(35,3); write('2. B=');
  40. for i:=1 to 3 do begin
  41. gotoxy(38+3*i,j);
  42. write(b[i]);
  43. end;
  44. gotoxy(10,10); write('3. A*A=');
  45. for i:=1 to 3 do begin
  46. for j:=1 to 3 do begin
  47. gotoxy(14+4*i,8+j);
  48. writeln(c[i,j]);
  49. end; end;
  50. gotoxy(35,10); write('4. (A*A)*B=');
  51. for i:=1 to 3 do begin
  52. gotoxy(43+5*i,7+j);
  53. writeln(d[i]);
  54. end;
  55. readkey;
  56. end; end;
  57. if y=2 then begin
  58. clrscr;
  59. textcolor(7);
  60. gotoxy(30,11); write('A=');
  61. for i:=1 to 3 do begin
  62. for j:=1 to 3 do begin
  63. gotoxy(28+4*i,9+j);
  64. writeln(a[i,j]:2);
  65. end; end;
  66. readkey;
  67. end; end;
  68. if y=3 then begin textbackground(3);
  69. clrscr;
  70. l:=(a[1,1]*((a[2,2]*a[3,3])-(a[2,3]*a[3,2])))-(a[1,2]*((a[2,1]*a[3,3])-(a[2,3]*a[3,1])))+(a[1,3]*((a[2,1]*a[3,2])-(a[2,2]*a[3,1])));
  71. textcolor(4); gotoxy(33,12); writeln('Определитель=',1:2:0);
  72. readkey;
  73. end;
  74. if y=4 then begin
  75. clrscr;
  76. l=-124;
  77. x:=-1;
  78. for i:=1 to 3 do begin
  79. for j:=1 to 3 do begin
  80. t[1,1]:=sqr(x)*((a[2,2]*a[3,3])-(a[2,3]*a[3,2])); t[2,1]:=(sqr(x)*(x))*((a[2,1]*a[3,3])-(a[3,1]*a[2,3]));
  81. t[3,1]:=(sqr(x)*(x)*(x))*((a[2,1]*a[3,2])-(a[2,2]*a[3,1])); t[1,2]:=(sqr(x)*(x))*((a[1,2]*a[3,3])-(a[3,2]*a[1,3]));
  82. t[2,2]:=(sqr(x)*(x)*(x))*((a[1,1]*a[3,3])-a[3,1]*a[1,3])); t[3,2]:=(sqr(x)*(x)*(x)*(x))*((a[1,1]*a[3,2])-(a[3,1]*a[1,2]));
  83. t[1,3]:=(sqr(x)*(x)*(x))*((a[1,2]*[2,3])-(a[2,2]*a[1,3])); t[2,3]:=(sqr(x)*(x)*(x)*(x))*((a[1,1]*a[2,3])-(a[2,1]*a[1,3]));
  84. t[3,3]:=(sqr(x)*(x)*(x)*(x)*(x))*((a[1,1]*a[2,2])-a[2,1]*a[1,2]));
  85. end; end;
  86. for i:=1 to 3 do begin
  87. for j:=1 to 3 do begin
  88. h[i,j]:=(1/l)*(t[i,j]);
  89. end; end;
  90. textcolor(4);
  91. gotoxy(9,11); write('Обратная матрица=');
  92. for i:=1 to 3 do begin
  93. for j:=1 to 3 do begin
  94. gotoxy(23+10*i,9+j);
  95. writeln(h[j,i]:2:6);
  96. end; end;
  97. readkey;
  98. end; if y=5 then begin textbackground(6); clrscr; l:=-124;
  99. d1:=(b[1]*((a[2,2]*a[3,3])-(a[2,3]*a[3,2])))-(a[1,2]*((b[2]*a[3,3])-(a[2,3]*b[3])))+(a[1,3]*((b[2]*a[3,2])-(a[2,2]*b[3])));
  100. d2:=(a[1,1]*((b[2]*a[3,3])-(a[2,3]*b[3])))-(b[1]*((a[2,1]*a[3,3])-(a[2,3]*a[3,1])))+(a[1,3]*((a[2,1]*b[3])-(b[2]*a[3,1])));
  101. d3:=(a[1,1]*((a[2,2]*b[3])-(b[2]*a[3,2])))-(a[1,2]*((a[2,1]*b[3])-(b[2]*a[3,1])))+(b[1]*((a[2,1]*a[3,2])-(a[2,2]*a[3,1])));
  102. x1:=d1/l; x2:=d2/l; x3:=d3/l; textcolor(7);
  103. gotoxy(35,10); write('x1='); writeln(x1:2:0);
  104. gotoxy(35,12); write('x2='); writeln(x2:2:0);
  105. gotoxy(35,14); write('x3='); writeln(x3:2:0);
  106. readkey;
  107. end;
  108. if y=6 then goto r;
  109. goto p;
  110. readkey;
  111. r:
  112. end.

Share with your friends:

Распечатать