# Error on mean calculation from random generator

**URL:** <https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125>\
**Category:** Questions\
**Created:** [September 27, 2023, 7:58pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125 "2023-09-27T19:58:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [September 27, 2023, 7:58pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125/1 "2023-09-27T19:58:42Z")

</div>

I have this activity that I’ve used for a couple of years now but my students are getting an error on one slide. I’m attaching the slide for assistance. It appears that when the student checks their answer they will get an “incorrect” if the list is showing “undefined”. I’m not sure why it is showing “undefined”. The “?” are can be ignored and the student response is ok. It’s the “undefined” that is causing the problem.

Thank you,

> **[Mean Calculation on Random Generator • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/651488a7435b30c3c5cfb558)**
>
> by Pamela Davis

---

<div class="post-metadata">

**Author:** ![pirsquared](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pirsquared](https://cl.desmos.com/u/pirsquared)\
**Post date:** [September 27, 2023, 10:16pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125/2 "2023-09-27T22:16:12Z")

</div>

A list defined by [1,6,…,max] can overshoot the upper limit - for example, if you do [1,6,…,20] it will give [1,6,11,16,21]. So the activity is sometimes looking for the 237th or 238th term of a 236-long list, hence the undefined.

You can ‘sanitise’ a list by having something like `s_0 = s[s>0]`, which will create a new list `s_0` that removes any undefined terms.

---

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [September 27, 2023, 10:33pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125/3 "2023-09-27T22:33:20Z")

</div>

> [@pirsquared](#):
>
> s\_0 = s[s\>0]

Thank you for getting back to me. I tried adding this as a line and I am still getting “undefined” in my random results and the mean as incorrect.

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [September 27, 2023, 10:40pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125/4 "2023-09-27T22:40:36Z")

</div>

Similar to another thread regarding undefined terms, try s[0\<s\<infinity].

---

<div class="post-metadata">

**Author:** ![pirsquared](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pirsquared](https://cl.desmos.com/u/pirsquared)\
**Post date:** [September 27, 2023, 10:51pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125/5 "2023-09-27T22:51:36Z")

</div>

Have you changed all of the other lists to now look at `s_0` rather than `s`? Remember `s` still has undefined terms in it.

---

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [September 28, 2023, 1:48pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125/6 "2023-09-28T13:48:44Z")

</div>

Unfortunately, I do not understand a lot of the programing and I don’t understand " Have you changed all of the other lists to now look at `s_0` rather than `s` ? Remember `s` still has undefined terms in it." because the only place I see “s” is line 4. I do not see it as part of any of the other statements. So I’m not sure what to do with: s\_0 = s[s\>0] or s[0\<s\<infinity]. Are these supposed to have their own command line in the “edit graph” or be part of other command lines or am I supposed to place these in the computation layer?

---

<div class="post-metadata">

**Author:** ![pirsquared](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pirsquared](https://cl.desmos.com/u/pirsquared)\
**Post date:** [September 28, 2023, 8:43pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125/7 "2023-09-28T20:43:06Z")

</div>

So at the moment, you have list `s` that picks every fifth value and sometimes looks for an item that doesn’t exist and therefore has an “undefined” at the end. This list is then used in the label of P (line 7) and the mean calculation on line 9. The mean can’t be defined if one of the terms in the list is undefined.

Daniel and I are suggesting you can sanitise this list by creating a new one, `s_0` or whatever you want to call it, that picks only the **defined** elements from `s`. Now you have a “clean” list, it’s _this_ that you need to use in lines 7 and 9, not the original `s` which still has the undefined term in it.

Does that make sense?

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [September 28, 2023, 10:56pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125/8 "2023-09-28T22:56:12Z")

</div>

Here’s a different way to index list L\_1. I added L\_index which is essentially a list of [1…5] repeated up to the length of L\_1. Then, rather than using an arithmetic sequence beginning with L\_0, I’m filtering L\_1 using the list L\_index where it is equivalent to L\_0. No worries of undefined values… [Desmos | Graphing Calculator](https://www.desmos.com/calculator/bdwll3fdsz)

---

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [September 29, 2023, 1:55pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125/9 "2023-09-29T13:55:13Z")

</div>

Thank you for explaining. I’m slowly learning the programing for the graphing calculator.

---

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [September 29, 2023, 1:55pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125/10 "2023-09-29T13:55:46Z")

</div>

Thank you! I made the changes that you gave and it works!

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [September 29, 2023, 3:43pm UTC](https://cl.desmos.com/t/error-on-mean-calculation-from-random-generator/5125/11 "2023-09-29T15:43:56Z")

</div>

You could also potentially replace the 5’s with a variable, if you wanted to change how you’re sampling.
