Forum > Beginners
[SOLVED] Need help to use slegsy in NumLib correctly
ikel:
Hi,
I'm running the following example with slegsy, but throw an access violation error.
The original example is located here; https://wiki.freepascal.org/NumLib_Documentation#Solving_systems_of_linear_equations_(unit_sle)
Here is the code.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program solve_sys_lin_eq; uses typ, sle, omv; const n = 4; A: array[1..n, 1..n] of ArbFloat = ( ( 5, 7, 6, 5), ( 7, 10, 8, 7), ( 6, 8, 10, 9), ( 5, 7, 9, 10) ); b: array[1..n] of ArbFloat = ( 57, 79, 88, 86 ); var x: array[1..n] of ArbFloat; b_test: array[1..n] of ArbFloat; ca: ArbFloat; i, j: Integer; term: Integer; begin WriteLn('Solve matrix system A x = b'); WriteLn; // Print A WriteLn('Matrix A = '); for i:= 1 to n do begin for j := 1 to n do Write(A[i, j]:10:0); WriteLn; end; WriteLn; // Print b WriteLn('Vector b = '); for i:= 1 to n do Write(b[i]:10:0); WriteLn; WriteLn; // Solve - select one of these methods //slegen(n, n, A[1, 1], b[1], x[1], ca, term); slegsy(n, n, A[1, 1], b[1], x[1], ca, term); //slegpd(n, n, A[1, 1], b[1], x[1], ca, term); if term = 1 then begin WriteLn('Solution vector x = '); for i:= 1 to n do Write(x[i]:10:0); WriteLn; WriteLn; omvmmv(A[1,1], n, n, n, x[1], b_test[1]); WriteLn('Check result: A x = (must be equal to b)'); for i:= 1 to n do Write(b_test[i]:10:0); WriteLn; end else WriteLn('Error'); ReadLn; end.
The error I get is ...
--- Code: Bash [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---$ ./SolveLinearEq.exeSolve matrix system A x = b Matrix A = 5 7 6 5 7 10 8 7 6 8 10 9 5 7 9 10 Vector b = 57 79 88 86 An unhandled exception occurred at $0000000100015539:EAccessViolation: Access violation $0000000100015539 $000000010000F35A $00000001000018D3 $0000000100001AD6 $000000010000DA20 $00000001000016C0 $00007FFC4F09257D $00007FFC5052AF28
Can someone help me to use slegsy correctly?
Thanks.
wp:
I tested your code with Laz 3.4/FPC 3.2.2 (32 bit and 64 bit), Laz main/FPC 3.2.2 (32 bit and 64 bit) and with Laz main/FPC main, all on Windows 11, and with Laz 3.4/FPC 3.2.2 on Kubuntu 24.04, and did not get an error. Which Laz/FPC versions are you using, and on with operating system?
ikel:
Hi wp,
I'm sorry, I mised out the important bit out. I am uing the following.
Lazarus 3.5 (rev lazarus_3_4-96-gcfd24b5c32)
FPC 3.2.3 x86_64-win64-win32/win64
Win 11.
Let me try the snippet on FPC 3.2.2. Thank you.
-ikel
ikel:
--- Quote from: wp on September 09, 2024, 12:13:15 am ---I tested your code with Laz 3.4/FPC 3.2.2 (32 bit and 64 bit), Laz main/FPC 3.2.2 (32 bit and 64 bit) and with Laz main/FPC main, all on Windows 11, and with Laz 3.4/FPC 3.2.2 on Kubuntu 24.04, and did not get an error. Which Laz/FPC versions are you using, and on with operating system?
--- End quote ---
wp, the snippet works when I use FPC 3.2.2 x86_64-win64-win32/win64. The snippet doesn't work on FPC 3.2.3 (fixes).
Thanks for your help!
-ikel
jamie:
So, I have an enquiry, all those other units you have in the USES list, were they also compiled with the 3.2.3 release?
Navigation
[0] Message Index
[#] Next page