Update a Single List Item
Update Single List Element Function #
Here is a function that updates a single element in a list:
Parameters #
- The list whose single element is changing.
- The one-based index of the element you're changing (e.g. pass in to change the third element).
- The new value you're replacing the element with.
How it Works #
This function works using Desmos's broadcasting feature. In the case of the function above, the piecewise function is run separately for every element of the list. This list essentially maps each element to its index— i.e. the first element is , the second element is , et cetera. What this means is that the piecewise condition is only true for the list element equal to , and since this list's elements are the same as its indices, the piecewise is only true for the th list item. This instance of the piecewise then evaluates to . Otherwise, it just uses the original value at that index in . In other words, only the th list item changes— everything else remains as-is. Again, because of broadcasting, in this context refers to an element of the list, not the list itself.