MHB Finding values in a 2 dimensional array

  • Thread starter Thread starter fvnn
  • Start date Start date
  • Tags Tags
    Array
Click For Summary
The discussion focuses on calculating values in a two-dimensional array B based on the sums of elements from a one-dimensional array A. The pseudo code provided iterates through indices to populate B[i][j] with the sum of A[k] for k ranging from i to j. An example is given where, for i=1 and j=3, B[1][3] equals 6 after summing A[1], A[2], and A[3]. Participants suggest executing the code manually and implementing it in a programming language like C for verification. The conversation emphasizes understanding array indexing and the summation logic.
fvnn
Messages
2
Reaction score
0
Here's the pseudo code:

Code:
for i := 1 to n { //i=1 and n=4
  for j := i to n { //j=1
   B[i][j] := 0
     for k := i to j {
       B[i][j] := B[i][j] + A[k]
     }
  }
}

This is what i understand from the code above - B values are from the sum of a values.
I want to know what the values of B[j] would be if A were A[1,2,3,4]. I don't need an answer i just need guidance on how to solve this.
 
Technology news on Phys.org
Do array indices start at 1?

Why don't you execute the code by hand and then write an actual program, say, in C to verify the result? For example, when $i=1$ and $j=3$ the inner loop makes three iterations:

B[1][3] := B[1][3] + A[1];
B[1][3] := B[1][3] + A[2];
B[1][3] := B[1][3] + A[3];

So the B[1][3] ends up with 1 + 2 + 3 = 6.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
Back
Top