Skocz do zawartości
Forum komputerowe PC Centre
JarekHP

[Pascal] problem z typami zmiennych

Rekomendowane odpowiedzi

Witam.

 

Mam problem z programem, który nie chce się poprawnie skompilować., wyskakuje błąd 'ERROR26: Type mismatch;

 

Problemem są zapewne typy zmiennych zdeklarowanych na początku, o których nie mam większego pojęcia.

 

 

{Temat: jacoby}

Program JJJ;

uses crt;  {modul wejsciowy programu}
type matrix =array[1..20,1..20] of extended;
    vector = array [1..20] of extended;
    var
      stopien, z:integer;
      macierz   :matrix;
      wart      :vector;
      rozw      :vector;
      Plik      :text;

procedure Jacobi (n         : integer;
                 var a     : matrix;
                 var b     : vector;
                 mit       : integer;
                 eps       : extended;
                 var x     : vector;
                 var it,st : integer);
{---------------------------------------------------------------------------}
{                                                                           }
{  The procedure Jacobi solves a system of linear equations by Jacobi's     }
{  iteration method.                                                        }
{  Data:                                                                    }
{    n   - number of equations = number of unknowns,                        }
{    a   - two-dimensional array containing elements of the matrix of the   }
{          system (changed on exit),                                        }
{    b   - one-dimensional array containing free terms of the system        }
{          changed on exit),                                                }
{    mit - maximum number of iterations in Jacobi's method,                 }
{    eps - accuracy of the solution,                                        }
{    x   - an array containing an initial approximation to the solution     }
{          (changed on exit).                                               }
{  Results:                                                                 }
{    x  - an array containing the solution,                                 }
{    it - number of iterations.                                             }
{  Other parameters:                                                        }
{    st - a variable which within the procedure Jacobi is assigned the      }
{         value of:                                                         }
{           1, if n<1,                                                      }
{           2, if the matrix of the system is singular,                     }
{           3, if the desired accuracy of the solution is not achieved      }
{              under mit iteration steps,                                   }
{           0, otherwise.                                                   }
{         Note: If st=1, then the elements of array x are not changed on    }
{               exit. If st=2, then x[i]=0 on exit (i=1,2,...,n), and if    }
{               st=3, then x contains the last approximation to the         }
{               solution.                                                   }
{  Unlocal identifiers:                                                     }
{    vector - a type identifier of extended array [q1..qn], where q1<=1 and }
{             qn>=n,                                                        }
{    matrix - a type identifier of extended array [q1..qn,q1..qn], where    }
{             q1<=1 and qn>=n.                                              }
{                                                                           }
{---------------------------------------------------------------------------}
var i,ih,k,kh,khh,lz1,lz2 : integer;
   max,r                 : extended;
   cond                  : Boolean;
   x1                    : vector;
begin
 if n<1
   then st:=1
   else begin
          st:=0;
          cond:=true;
          for k:=1 to n do
            x1[k]:=0;
          repeat
            lz1:=0;
            khh:=0;
            for k:=1 to n do
              begin
                lz2:=0;
                if a[k,k]=0
                  then begin
                         kh:=k;
                         for i:=1 to n do
                           if a[i,k]=0
                             then lz2:=lz2+1;
                         if lz2>lz1
                           then begin
                                  lz1:=lz2;
                                  khh:=kh
                                end
                       end
              end;
            if khh=0
              then cond:=false
              else begin
                     max:=0;
                     for i:=1 to n do
                       begin
                         r:=abs(a[i,khh]);
                         if (r>max) and (x1[i]=0)
                           then begin
                                  max:=r;
                                  ih:=i
                                end
                       end;
                     if max=0
                       then begin
                              st:=2;
                              for i:=1 to n do
                                x[i]:=0
                            end
                       else begin
                              for k:=1 to n do
                                begin
                                  r:=a[khh,k];
                                  a[khh,k]:=a[ih,k];
                                  a[ih,k]:=r
                                end;
                              r:=b[khh];
                              b[khh]:=b[ih];
                              b[ih]:=r;
                              x1[khh]:=1
                            end
                   end
          until not cond or (st=2);
          if not cond
            then begin
                   it:=0;
                   repeat
                     it:=it+1;
                     if it>mit
                       then begin
                              st:=3;
                              it:=it-1
                            end
                       else begin
                              for i:=1 to n do
                                begin
                                  r:=b[i];
                                  for k:=1 to n do
                                    if k<>i
                                      then r:=r-a[i,k]*x[k];
                                  x1[i]:=r/a[i,i]
                                end;
                              max:=abs(x[1]-x1[1]);
                              for i:=2 to n do
                                begin
                                  r:=abs(x[i]-x1[i]);
                                  if r>max
                                    then max:=r
                                end;
                              if max<=eps
                                then cond:=true;
                              for i:=1 to n do
                                x[i]:=x1[i]
                            end
                   until (st=3) or cond
                 end
        end
end;



Procedure wejscie; {procedura wczytujaca dane z pliku tekstowego}
 var n1,n2 :integer;

 Begin
    assign  (plik,'c:\wczytaj.txt');{wczytywanie danych z pliku wczytaj.txt}
    reset (plik);
    readln (plik,stopien);   {wczytanie stopnia macierzy}
    for n1:=1 to stopien do
    for n2:=1 to stopien do
    read(plik,macierz[n1,n1]);{wczytanie macierzy}
    for n1:=1 to stopien do
    read (plik,wart[n1]); {wczytanie wektora}
    close(plik); {zamkniecie pliku}
 end;

 Procedure zapisz; {procedura zapisujaca wynik}
 var n1:integer;

 begin
    assign(plik,'c:\rozwiazanie.txt');{utworzenie pliku "rozwiazanie.txt" zawierajacego rozwiazanie}
    rewrite(plik);
    for n1:=1 to stopien do
    write(plik,rozw[n1]:10:5);{zapis rozwiazania w pliku}
    close(plik);{zamkniecie pliku}
 end;

 begin
   clrscr;{czyszczenie ekranu}
   wejscie; {procedura wejscie}
   jacobi(stopien,macierz,wart,rozw,z);{procedura}
   zapisz; {procedura zapisania}
   writeln('Plik z rozwiazaniem zapisany na dysku c:, nazwa rozwiaza.txt');{informacja odnosnie polozenia pliku z rozwiazaniem}
   repeat until keypressed;

 end.

 

Proszę o pomoc, bo już mi głowa pęka.

Pozdrawiam.

Edytowane przez JarekHP

Udostępnij tę odpowiedź


Odnośnik do odpowiedzi
Udostępnij na innych stronach

×
×
  • Dodaj nową pozycję...