Kamis, 26 Maret 2020

SMALL BASIC: Create Matrix Diagonal zero with Loop For

Hi, SMALL Basic programmer, welcome.

In this tutorial we will create a diagonal matrix with random number values. The program is like below:

TextWindow.WriteLine("Enter the matrix size that you like to enter: ")
ms = TextWindow.Read()

For i = 0 To ms
  For j = 0 To ms
    if array[i][j] <> 0 Then
      If i <> j then
      array[i][j] = Math.GetRandomNumber(10)
      array[j][i] = array[i][j]
      ElseIf i = j then
      array[i][j] = 0
      EndIf
    EndIf
  EndFor
EndFor

Creating diagonal zero matrix is essentially give value to both (i,j) and (j,i) if (i,j) is still empty or still not initialized yet for how many rows and colomns that you like.

Fact about mesh

Every line is neighbor list of that line or a.k.a of that element. So for instance you want to make a program like this: print all the neighbor and the neighbor

Print all the neighbor of the first first neighbor of node 1
textwindow.writeline("Enter the node: ")
node = textwindow.read()
textwindow.writeline("Enter the neighbor you want to print its neighbor:")
neighbor = textwindow.read()

or this can be said like this:
textwindow.writeline("Enter the node: ")
node = textwindow.read()
textwindow.writeline("Enter the index of the neighbor that you want us to print its neighbor: ")
firstneighborindex = textwindow.read()

'And then read the relationship_array


Every step kedalam, will reduce 2 * i neighbor.


Tidak ada komentar:

Posting Komentar