Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>For my understanding, for a "A,b = create_matrix_1(4,4)" the matrix A is 16*16; b is 16*1</p> </blockquote> <p>Not necessarily: in the code above we don't have the definitions of the functions <code>lil_matrix</code> and <code>zeros</code>. The statements before the <code>for</code> loop only say that <code>A</code> is equal to the value returned by the function <code>lil_matrix</code> when the values <code>(n*m, n*m)</code> are passed to it as a tuple. On the other hand <code>b</code> is equal to the value returned by the function <code>zeros</code>, when you pass to it <code>n*m</code>.</p> <p>Then there is the loop section. Basically, there are 2 nested loops, i.e. there are two iterators, i and j, that are incremented respectively from 0 to n-1 and from 0 to m-1; so, assuming n = 4 and m = 4:</p> <p>1) We start by iterating through all values of <code>j</code>, having <code>i=0</code>:</p> <pre><code>Iteration Value of index 1 0+0*4 2 0+1*4 3 0+2*4 4 0+3*4 </code></pre> <p>2) Now that all <code>j</code> values, from <code>j=0</code> to <code>j=m-1</code>, have been cycled through, we increment <code>i</code>, and again we iterate through all values of <code>j</code>:</p> <pre><code>5 1+0*4 6 1+1*4 7 1+2*4 8 1+3*4 </code></pre> <p>3) Then we repeat the same cycle for <code>i=2</code>, <code>i=3</code> etc., until <code>i=n-1</code>.</p> <p>Now we get to the <code>if</code> and <code>else</code> blocks. For each of the cycles described above, if we have a boundary value, i.e. either <code>i</code> or <code>j</code> are at the first or last iteration of the cycle (e.g. either <code>i</code> or <code>j</code> are <code>= 0</code>, or <code>i=n-1</code> or <code>j=m-1</code>) then the values of <code>A</code> and <code>b</code> are not any more the ones described at the beginning of this answer, but are changed according to the two lines after the line starting with <code>if</code>. If instead the values of <code>i</code> or <code>j</code> are not boundary values, but are interior nodes, the values of <code>A</code> and <code>b</code> are changed according to the lines after the <code>else</code> statement. </p> <p>Both the statements in the <code>if</code> and in the <code>else</code> section only change some of the elements of <code>A</code> and <code>b</code>, which are arrays. Looking at the code, <code>A</code> must be a bidimensional array (matrix), as you pointed out correctly in your question, and <code>b</code> is a one dimensional array (vector). (In Python, by the way, arrays are actually lists, but I will use here the general term array). Both in the <code>if</code> and <code>else</code> block we have the <code>index</code> keyword: e.g. <code>b[index]</code>means that the value of <code>b</code> that we are modifying is the Nth value of <code>b</code>, where <code>index</code> = N. For <code>A</code> we have two values in the square brackets, since <code>A</code> is a matrix. By the way there is in my opinion an error in the syntax since when you select a single value in a matrix you don't use the comma, e.g. you don't write <code>A[x, y]</code> but <code>A[x][y]</code> (the comma can only be used when you define the matrix, not when you select one of its values). However both <code>A</code> and <code>b</code> are created in the first place using functions not included in this code so we don't know much more than that. </p> <p>Other than <code>lil_matrix</code> and <code>zeros</code>, the other function which you need to investigate, because its definition is not included in this code, is <code>linspace</code>: this is used at the beginning to create the variables <code>x</code> and <code>y</code> which then are used in the <code>if</code> block.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload