sharkos Posted January 30, 2009 Posted January 30, 2009 Im trying to write Gaussian elimination method. I have array (column 0 and row 0 are empty always): 11 | 12 | 13 | 14 21 | 22 | 23 | 24 31 | 32 | 33 | 34 In Stage 1 first array ($A) is modyfied by function 'calc' and saved in second array and it looks like these ( * - updated): 11 | 12 | 13 | 14 21* | 22* | 23* | 24* 31* | 32* | 33* | 34* In Stage 2 second array ($A2) is modyfied and saved in to $A3, should look like these: 11 | 12 | 13 | 14 21 | 22 | 23 | 24 31 | 32* | 33* | 34* But it dosent. Function 'calc' is called 3 times like it should be, but array is changed like these: 11 | 12 | 13 | 14 21(+1)* | 22(+1)* | 23(+1)* | 24(+1)* 31(+2)* | 32* | 33* | 34* Heres my code: expandcollapse popup#Include <Array.au3> $gi=3 $gj=$gi+1 Dim $A[$gi+1][$gj+1] Dim $A2[$gi+1][$gj+1] Dim $A3[$gi+1][$gj+1] $A[1][1] = 2 $A[1][2] = 2 $A[1][3] = 2 $A[1][4] = 2 $A[2][1] = 1 $A[2][2] = 2 $A[2][3] = 4 $A[2][4] = 0 $A[3][1] = 2 $A[3][2] = 2 $A[3][3] = 1 $A[3][4] = -2 $A2=$A $A3=$A ; Stage 1 <===================== For $ti=2 To $gi Step +1 For $tj=1 To $gj Step +1 $A2[$ti][$tj] = Call("calc", $A, $ti, $tj, 1) Next Next _ArrayDisplay($A2, "Window") ;Stage 2 <===================== For $ti=3 To $gi Step +1 For $tj=2 To $gj Step +1 $A3[$ti][$tj] = Call("calc", $A2, $ti, $tj, 2) Next Next _ArrayDisplay($A3, "Window") Func calc($T, $i, $j, $c) $temp = $T[$i][$j] - ($T[$i][$c]/$T[$c][$c]) * $T[$c][$j] MsgBox(0,"","$T["&$i&"]["&$j&"] - ($T["&$i&"]["&$c&"]/$T["&$c&"]["&$c&"]) * $T["&$c&"]["&$j&"] = "&$temp);FOR DEBUG ONLY Return $temp EndFunc Whats wrong in Step 2?
Authenticity Posted January 30, 2009 Posted January 30, 2009 11 | 12 | 13 | 14 21 | 22 | 23 | 24 31 | 32* | 33* | 34* If this is the desired result then I see you need to take a good break, lol, this is exactly what the second stage does. Additionally, you can just call the function like this calc($A, $ti, $tj, 1) without using the call function. Step +1 is the default for the For...Next loop, no need to include it.
sharkos Posted January 30, 2009 Author Posted January 30, 2009 Input:Step 1 result:Step 2 result:Step 2 desired result:Whats going on?
KaFu Posted January 30, 2009 Posted January 30, 2009 (edited) expandcollapse popup#Include <Array.au3> $gi=3 $gj=$gi+1 Dim $A[$gi+1][$gj+1] Dim $A2[$gi+1][$gj+1] Dim $A3[$gi+1][$gj+1] $A[1][1] = 2 $A[1][2] = 2 $A[1][3] = 2 $A[1][4] = 2 $A[2][1] = 1 $A[2][2] = 2 $A[2][3] = 4 $A[2][4] = 0 $A[3][1] = 2 $A[3][2] = 2 $A[3][3] = 1 $A[3][4] = -2 $A2=$A ; Stage 1 <===================== For $ti = 2 To $gi For $tj=1 To $gj $A2[$ti][$tj] = calc($A, $ti, $tj, 1) Next Next _ArrayDisplay($A2, "Window") $A3=$A2 ;Stage 2 <===================== For $ti = 3 To $gi For $tj=2 To $gj $A3[$ti][$tj] = calc($A2, $ti, $tj, 2) Next Next _ArrayDisplay($A3, "Window") Func calc($T, $i, $j, $c) $temp = $T[$i][$j] - ($T[$i][$c]/$T[$c][$c]) * $T[$c][$j] ;MsgBox(0,"","$T["&$i&"]["&$j&"] - ($T["&$i&"]["&$c&"]/$T["&$c&"]["&$c&"]) * $T["&$c&"]["&$j&"] = "&$temp);FOR DEBUG ONLY Return $temp EndFunc Edited January 30, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
sharkos Posted January 30, 2009 Author Posted January 30, 2009 Thx KaFu So problem was $A3=$A2 it should be after Step 1
KaFu Posted January 30, 2009 Posted January 30, 2009 Thx KaFu So problem was $A3=$A2 it should be after Step 1 De Nada ... maybe I should've said so , will work on my replying behavior... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now