Recent

Author Topic: Help with OLD code  (Read 852 times)

juanirias

  • Full Member
  • ***
  • Posts: 103
Help with OLD code
« on: April 11, 2026, 06:07:43 pm »
Hi, I need to compile a math unit, but I'm having trouble.

The unit NUMLIB code is here:
https://github.com/alrieckert/freepascal/tree/master/packages/numlib

And the function is "determinant", but I'm not getting it to work.
https://wiki.lazarus.freepascal.org/NumLib_Documentation#Determinant_of_a_matrix_(unit_det)


Ragards, JUAN

Thaddy

  • Hero Member
  • *****
  • Posts: 19129
  • Glad to be alive.
Re: Help with OLD code
« Reply #1 on: April 11, 2026, 06:18:51 pm »
numlib is a standard fpc code library, unless there is a naming conflict, so will port without issue if it is the same "numlib".
It is in .\packages\numlib
It is also maintained. (when necessary)

Don't use third party links when it is a standard package, always use the package FPC provides.....

Since you are using the same numlib, only much older, if it does not port when using the correct one, plz report back.
The author, marcov, is a core developer and will help you in that case.

In a standard installation numlib compiles out-of-the-box and is in the path.
To my knowledge there are no interface changes apart for 32->64 bit.
« Last Edit: April 11, 2026, 06:27:32 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

juanirias

  • Full Member
  • ***
  • Posts: 103
Re: Help with OLD code
« Reply #2 on: April 11, 2026, 06:26:29 pm »
I cant run well


Code: Pascal  [Select][+][-]
  1. program determinant_spd_matrix;   // "spd" = symmetric positive definite
  2.  
  3. uses
  4.   numlib;
  5.  
  6. const
  7.   n = 4;
  8.  
  9. const
  10.   a: array[1..n, 1..n] of ArbFloat = (
  11.     ( 4,  2,  4,  1)
  12.     (30, 20, 45, 12)
  13.     (20, 15, 36, 10)
  14.     (35, 28, 70, 20)
  15.   );
  16.  
  17. var
  18.   f: ArbFloat;
  19.   k: Integer;
  20.   term: Integer = 0;
  21.   i, j: Integer;
  22.  
  23. begin
  24.   // write input matrix
  25.   WriteLn('A = ');
  26.   for i := 1 to n do begin
  27.     for j := 1 to n do
  28.       Write(a[i, j]:10:0);
  29.     WriteLn;
  30.   end;
  31.   WriteLn;
  32.  
  33.   // Calculate determinant of symmetric positive definite matrix
  34.   detgpd(n, n, a[1, 1], f, k, term);
  35.  
  36.   // or uncomment to use one of the other methods
  37.   // detgen(n, n, a[1, 1], f, k, term);
  38.   // detgsy(n, n, a[1, 1], f, k, term);
  39.  
  40.   if term = 1 then
  41.     WriteLn('Determinant of A = ', f * intpower(8, k):0:9, ' (k = ', k, ')')
  42.   else
  43.     WriteLn('Incorrect input');
  44. end.
  45.  
  46.  


determinant_spd_matrix.pas(15,4) Fatal: Syntax error, "," expected but ";" found


Thaddy

  • Hero Member
  • *****
  • Posts: 19129
  • Glad to be alive.
Re: Help with OLD code
« Reply #3 on: April 11, 2026, 06:34:25 pm »
Corrected code, Your code would never have worked but this code does:
Code: Pascal  [Select][+][-]
  1. program determinant_spd_matrix;   // "spd" = symmetric positive definite
  2. {$mode delphi}
  3. uses
  4.   math, typ, numlib; //  2/3 forgotten???
  5.  
  6. const
  7.   n = 4;
  8.  
  9. const
  10.   // here all comma's forgotten???
  11.   a: array[1..n, 1..n] of ArbFloat = (
  12.     ( 4,  2,  4,  1),
  13.     (30, 20, 45, 12),
  14.     (20, 15, 36, 10),
  15.     (35, 28, 70, 20)
  16.   );
  17.  
  18. var
  19.   f: ArbFloat;
  20.   k: Integer;
  21.   term: Integer = 0;
  22.   i, j: Integer;
  23.  
  24. begin
  25.   // write input matrix
  26.   WriteLn('A = ');
  27.   for i := 1 to n do begin
  28.     for j := 1 to n do
  29.       Write(a[i, j]:10:0);
  30.     WriteLn;
  31.   end;
  32.   WriteLn;
  33.  
  34.   // Calculate determinant of symmetric positive definite matrix
  35.   detgpd(n, n, a[1, 1], f, k, term);
  36.  
  37.   // or uncomment to use one of the other methods
  38.   // detgen(n, n, a[1, 1], f, k, term);
  39.   // detgsy(n, n, a[1, 1], f, k, term);
  40.  
  41.   if term = 1 then
  42.     WriteLn('Determinant of A = ', f * intpower(8, k):0:9, ' (k = ', k, ')')
  43.   else
  44.     WriteLn('Incorrect input');
  45. end.

It wouldn't even have worked back in the old days: too many mistakes....
Note it does not work if the correct library isn't available. but that code is also included: the shared library is tpnumlib.pas which you should compile first.
« Last Edit: April 11, 2026, 07:09:15 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

MathMan

  • Hero Member
  • *****
  • Posts: 501
Re: Help with OLD code
« Reply #4 on: April 11, 2026, 06:41:37 pm »
@Thaddy,

Totally correct, no question. However you missed the point that the code is a direct copy of the Numlib wiki webpage  ;)

Cheers,
MathMan

Thaddy

  • Hero Member
  • *****
  • Posts: 19129
  • Glad to be alive.
Re: Help with OLD code
« Reply #5 on: April 11, 2026, 06:43:23 pm »
Then change the wiki page: I just spend a little time testing it....  %) :o
And it works. Also 64 bit:
Code: Text  [Select][+][-]
  1. A =
  2.          4         2         4         1
  3.         30        20        45        12
  4.         20        15        36        10
  5.         35        28        70        20
  6.  
  7. Determinant of A = 0.000000000 (k = 2)

I have no opinion about the correctness of the result. Compiled win64-11-fpc-trunk. It probably is correct because of the check.
« Last Edit: April 11, 2026, 06:49:46 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

MathMan

  • Hero Member
  • *****
  • Posts: 501
Re: Help with OLD code
« Reply #6 on: April 11, 2026, 06:59:10 pm »
I did just that after my first reply - just took a while to create account, etc.

Should be correct now.

juanirias

  • Full Member
  • ***
  • Posts: 103
Re: Help with OLD code
« Reply #7 on: April 11, 2026, 08:08:15 pm »
Must be the linux distro...


sorry

I still stuck

Thaddy

  • Hero Member
  • *****
  • Posts: 19129
  • Glad to be alive.
Re: Help with OLD code
« Reply #8 on: April 11, 2026, 08:12:04 pm »
That can be the case , but give me a few seconds....
Yes the code is windows oriented. No direct UNIX support.
It should work, though, but I have to check the exports.
One or some of the parts already wants libtpnumlib.so. with a wrong name or place.
That is fixable. <logging off for the night, though>
« Last Edit: April 11, 2026, 08:28:26 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

wp

  • Hero Member
  • *****
  • Posts: 13507
Re: Help with OLD code
« Reply #9 on: April 12, 2026, 12:49:15 am »
I had done a major reconstruction of the determinants chapter in April 2017, and it seems that unfortunately some sub-chapters were mixed up on this occasion. Looked through the history and recreated the original parts. Tested the determinant demos in Linux - working fine.

Use the uses clause as given in the wiki samples. I did not test "uses numlib".
« Last Edit: April 12, 2026, 01:03:39 am by wp »

Thaddy

  • Hero Member
  • *****
  • Posts: 19129
  • Glad to be alive.
Re: Help with OLD code
« Reply #10 on: April 12, 2026, 08:17:11 am »
@wp
Thanks. Yes it works. Was too late for me yesterday.

@juanirias
It is not the Linux distro, that is agnostic for this code.
Did you get it to work? Otherwise ask again.

Just make sure the library is compiled before the program and make sure the uses clause is correct.
« Last Edit: April 12, 2026, 08:24:29 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

 

TinyPortal © 2005-2018