Note that there are some explanatory texts on larger screens.

plurals
  1. POMathematica Index Equation (basic algebra)
    primarykey
    data
    text
    <p>I am currently working on a Mathematica project to calculate Riemann's sums and put them in a table. I am having trouble printing the row numbers (intervals). (The row numbers are also parameters to the secondary functions). I don't know of any way to just access the index of the iterator in a Mathematica Table, so I am trying to compute them using the function parameters.</p> <p>Here is an example of what I'd like to print, for the integral of x^2 over the range {0, 1}, with 10 subdivisions.</p> <pre><code>tableRiemannSums[#^2 &amp;, {0, 1}, 10] </code></pre> <p><img src="https://i.stack.imgur.com/Oo8UA.jpg" alt="enter image description here"></p> <p>I need to figure out what the index of each iteration is, based on the value of the current subdivision k, the range of the integral {a, b}, and the number of subdivisions, n. Below is the main piece of code. </p> <pre><code>tableRiemannSums[fct_, {a_, b_}, n_] := Table[{'insert index here', leftRiemannSum[fct, {a, b}, 'insert index here'], rightRiemannSum[fct, {a, b}, 'insert index here']}, {k, a, b - (N[b - a]/n), N[b - a]/n}] </code></pre> <p>In the above equation, the line </p> <pre><code>{k, a, b - (N[b - a]/n), N[b - a]/n}] </code></pre> <p>means the range of the table is k as k goes from 'a' to 'b - ((b - a)/n)' in steps of size '(b - a)/n'.</p> <p>In each of the places where my code says 'insert index here,' I need to put the same equation. Right now, I am using 'n * k + 1' to calculate the index, which is working for positive ranges, but breaks when I have a range like {a,b} = {-1, 1}. </p> <p>I think this is a fairly straightforward algebra problem, but I have been racking my brain for hours and can't find a general equation. </p> <p>(I apologize if this is a duplicate question - I tried searching through the Stack overflow archives, but had a hard time summarizing my question into a few key words.)</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. 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