Create list of values with arbitrary index and the use it in a function - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-11-15T00:55:35Z https://mathematica.stackexchange.com/feeds/question/182736 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/182736 1 Create list of values with arbitrary index and the use it in a function Felipe Gonzalez https://mathematica.stackexchange.com/users/59327 2018-09-27T21:08:27Z 2018-09-27T21:32:01Z <p>I have the following generating functions:</p> <p><span class="math-container">\$l_{2i-1}=l_{1}-(i-2)(w+s)\$</span> with <span class="math-container">\$i\geq 2\$</span> and <span class="math-container">\$l_{2i}=l_{2}-(i-1)(w+s)\$</span> with <span class="math-container">\$i\geq 2\$</span>, so the first one is for odd index and the second for even index. Then I need to use the two for a function, let´s say a sum, So i'm going to need <span class="math-container">\$l_{1},l_2,l_3,...\$</span> etc but these are generated from the two different functions, so how can I call the <span class="math-container">\$l_{odd}\$</span> using the first function and <span class="math-container">\$l_{even}\$</span> using the second function in the same sum ?</p> <p>I tried simply defining my first function like f[2*i_-1] but it doesn´t work :(</p> <p>Many thanks,</p> https://mathematica.stackexchange.com/questions/182736/-/182737#182737 1 Answer by bill s for Create list of values with arbitrary index and the use it in a function bill s https://mathematica.stackexchange.com/users/1783 2018-09-27T21:26:48Z 2018-09-27T21:32:01Z <p>One way is to use OddQ and EvenQ. For example:</p> <pre><code>m[x_] := x^2 /; OddQ[x] m[x_] := 5 x^3 /; EvenQ[x] </code></pre> <p>defines m differently for odd and even arguments. For your f, maybe something like </p> <pre><code>f[x_] := l1 - (x - 2) (w + s) /; OddQ[x] f[x_] := l2 - (x - 1) (w + s) /; EvenQ[x] </code></pre>