Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Determinant and Triangular
12-27-2009, 06:04 PM
Post: #1
Determinant and Triangular
Here's the program that will form your square matrix to upper/lower triangular(as u like);and then will give you the determinant of the following matrix,There you go(again the same issue,Long code...) :
Code:
Program Lower_And_Upper_Triangular(input,output);
  (*Programmer S-T,Number:8811021 Programmer:Alireza Date:4,12,2009
    This program will input a matrix and will output lower/Upper triangular
    form of it*)
  Uses CRT;
  Type
    Mat=Array[1..30,1..30] Of real;
  Var
    I,J,L,M,Rows,Form:Integer;
    Matrix:Mat;
    K,Multi:real;
  Procedure ReadingMatrix(Var Matrix:Mat;Rows:integer);
    Var
      ii,jj:integer;
      Element:real;
    Begin
      Writeln(' Please enter the elements of your ',Rows,' X ',Rows,' Matrix');
      For ii:=1 To Rows Do
        Begin
          For jj:=1 To Rows Do
            Begin
              Read(Element);
              Matrix[ii,jj]:=Element;
            End;
        End;
    End;
   Procedure PrintingMatrix(Matrix:Mat;Rows:integer);
      Var
        ii,jj:integer;
        Element:real;
    Begin
      Writeln;
      Writeln(' Here are your matrix ');
      Textcolor(Green);
      For ii:=1 To Rows Do
        Begin
          For jj:=1 To Rows Do
            Begin
              Write(Matrix[ii,jj]:5:2);
            End;
          Writeln;
        End;
    End;
Begin
  CLRSCR;
  TextColor(yellow);
  Writeln('Please Enter number of your matrix`s Rows');
  Readln(Rows);
  ReadingMatrix(Matrix,Rows);
  Writeln('Now If you want your matrix in Lower triangular Form Press 1');
  Writeln('Now If you want your matrix in Upper triangular Form Press 2');
  Read(Form);
  Case Form OF

    1 : Begin
        For L:=Rows DownTo 2 Do
          Begin
            For I:=1 tO L-1 Do
              Begin
                If Matrix[I,L]=0 Then
                  Begin
                  End
                Else
                  If Matrix[L,L]=0 Then
                    Begin
                      For M:=Rows DownTo 1 Do
                        Begin
                          Matrix[L,M]:=Matrix[i,M]+Matrix[L,M];
                        End;
                    End;
                  K:=0;
                  K:=(-1)*Matrix[I,L]/Matrix[L,L];
                  For J:=Rows DownTo 1 Do
                    Begin
                      Matrix[I,J]:=K*Matrix[L,J]+Matrix[I,J];
                    End;
              End;
          End;
        Multi:=1;
        For I:=1 To Rows Do
          Begin
            Multi:=Multi*Matrix[i,i];
          End;
        PrintingMatrix(Matrix,Rows);
        Writeln;
        Write('Your matrix determinant is -> ');
        Textcolor(Red);
        Write(' ',Multi:7:3);
        End;
    2 : Begin
        For L:=1 To Rows-1 Do
          Begin
            For I:=Rows DownTo L+1 Do
              Begin
                If Matrix[I,L]=0 Then
                  Begin
                  End
                Else
                  If Matrix[L,L]=0 Then
                    Begin
                      For M:=Rows DownTo 1 Do
                        Begin
                          Matrix[L,M]:=Matrix[i,M]+Matrix[L,M];
                        End;
                    End;
                  K:=0;
                  K:=(-1)*Matrix[I,L]/Matrix[L,L];
                  For J:=Rows DownTo 1 Do
                    Begin
                      Matrix[I,J]:=K*Matrix[L,J]+Matrix[I,J];
                    End;
              End;
          End;
          Multi:=1;
          For I:=1 To Rows Do
            Begin
              Multi:=Multi*Matrix[i,i];
            End;
          PrintingMatrix(Matrix,Rows);
          Writeln;
          Write('Your matrix determinant is -> ');
          Textcolor(Red);
          Write(' ',Multi:7:3);
        End;
  End;
  Textcolor(White);
  Delay(1500);
  Writeln;
  Writeln;
  Writeln('CODED BY ALIREZA_M');
  Repeat
  Until Keypressed;
End.

Gholamreza Takhti
who was he? find out
Find all posts by this user
Quote this message in a reply
12-27-2009, 07:35 PM
Post: #2
RE: Determinant and Triangular
Very good code and algorithm ! I am impressed, good job !
For this you need to know maths and 2-dimensional arrays !

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
12-27-2009, 09:14 PM
Post: #3
RE: Determinant and Triangular
(12-27-2009 07:35 PM)drdebcol Wrote:  Very good code and algorithm ! I am impressed, good job !
For this you need to know maths and 2-dimensional arrays !
Thanks Cool

Gholamreza Takhti
who was he? find out
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: