# Evaluate function

**URL:** <https://cl.desmos.com/t/evaluate-function/2270>\
**Category:** Questions\
**Created:** [December 30, 2020, 2:00pm UTC](https://cl.desmos.com/t/evaluate-function/2270 "2020-12-30T14:00:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Svetlana\_Yushmanova](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/svetlana_yushmanova/32/479_2.png) [@Svetlana\_Yushmanova](https://cl.desmos.com/u/Svetlana_Yushmanova)\
**Post date:** [December 30, 2020, 2:00pm UTC](https://cl.desmos.com/t/evaluate-function/2270/1 "2020-12-30T14:00:12Z")

</div>

> **[Belopp • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/5fe9f21e3820c20cc50f3bf3)**
>
> by Svetlana Yushmanova

In slide 10 I would like to have a second column which gives abs(first column)  
How do I do that?

---

<div class="post-metadata">

**Author:** ![Svetlana\_Yushmanova](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/svetlana_yushmanova/32/479_2.png) [@Svetlana\_Yushmanova](https://cl.desmos.com/u/Svetlana_Yushmanova)\
**Post date:** [December 31, 2020, 9:52am UTC](https://cl.desmos.com/t/evaluate-function/2270/3 "2020-12-31T09:52:50Z")

</div>

Thank you very much!  
For my future projects, if you have time, can you please explain if you have time

why the extra “a” in definition of the function, do I always need it?

is the backslash just for latex or does it have other meaning here?

and what does ${} generally do, is it referring to a variable defined elsewhere?

---

<div class="post-metadata">

**Author:** ![Susan\_Lauer](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/susan_lauer/32/1832_2.png) [@Susan\_Lauer](https://cl.desmos.com/u/Susan_Lauer)\
**Post date:** [December 31, 2020, 3:52pm UTC](https://cl.desmos.com/t/evaluate-function/2270/4 "2020-12-31T15:52:45Z")

</div>

You don’t need a variable in simpleFunction (see [this post](https://cl.desmos.com/t/adding-a-math-type-fraction-to-a-note-when-using-cl/255/15)) For simpleFunction, you can put more variables, so if you wanted to do an average rounded to two places, you might use this code:

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/5/529ac026c82f4af81a909e05b31f83857024b5f0.png)

Note that cellContent takes a string, and simpleFunction returns a number. Keeping track of where you need numbers vs. strings vs. LaTeX is the tricky part. Looking at lots of examples of other code can help there.

The function \abs() is a predefined LaTeX function. So is the \round( , ) used here, and the \frac{ }{ } used at the link. You can see examples of LaTeX symbols [here](https://www.desmos.com/calculator/pn7bbk78v5).

---

<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:** [December 31, 2020, 7:11pm UTC](https://cl.desmos.com/t/evaluate-function/2270/5 "2020-12-31T19:11:12Z")

</div>

Doesn’t your code just display the latex `abs(a)` for the cellContents? You didn’t actually use your function, `abs`.

---

<div class="post-metadata">

**Author:** ![Susan\_Lauer](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/susan_lauer/32/1832_2.png) [@Susan\_Lauer](https://cl.desmos.com/u/Susan_Lauer)\
**Post date:** [December 31, 2020, 8:11pm UTC](https://cl.desmos.com/t/evaluate-function/2270/6 "2020-12-31T20:11:51Z")

</div>

I was just giving a small list of examples.

---

<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:** [January 1, 2021, 1:04am UTC](https://cl.desmos.com/t/evaluate-function/2270/7 "2021-01-01T01:04:36Z")

</div>

You stated:

> [@Susan\_Lauer](#):
>
> To automatically evaluate the absolute value of the 1st column, put this in Table10 CL:

I was clarifying that the code following will not _evaluate_ the absolute value.

---

<div class="post-metadata">

**Author:** ![Susan\_Lauer](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/susan_lauer/32/1832_2.png) [@Susan\_Lauer](https://cl.desmos.com/u/Susan_Lauer)\
**Post date:** [January 1, 2021, 1:19am UTC](https://cl.desmos.com/t/evaluate-function/2270/8 "2021-01-01T01:19:18Z")

</div>

Good catch, and you’re right! It should have been:

```auto
abs = simpleFunction("\abs(a)","a")
cellContent(1,2): when this.cellContent(1,1)="" "" otherwise "abs(${this.cellContent(1,1)})"
cellContent(2,2): when this.cellContent(2,1)="" "" otherwise "abs(${this.cellContent(2,1)})"

```

Svetlana fixed it in her activity already. Sorry for the mixup.

---

<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:** [January 1, 2021, 7:59pm UTC](https://cl.desmos.com/t/evaluate-function/2270/9 "2021-01-01T19:59:54Z")

</div>

Well to evaluate it, it should be  
`..."${abs.evaluateAt(this.cellNumericValue(1,1))}"`

---

<div class="post-metadata">

**Author:** ![Susan\_Lauer](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/susan_lauer/32/1832_2.png) [@Susan\_Lauer](https://cl.desmos.com/u/Susan_Lauer)\
**Post date:** [January 1, 2021, 9:36pm UTC](https://cl.desmos.com/t/evaluate-function/2270/10 "2021-01-01T21:36:14Z")

</div>

That’s right. Argh.  
I had this first, then I mangled it. Sorry. I’ve deleted the erroneous posts.

```auto
abs = simpleFunction("\abs(a)","a")
cellContent(1,2): when this.cellContent(1,1)="" "" otherwise "${abs.evaluateAt(this.cellNumericValue(1,1))}"
cellContent(2,2): when this.cellContent(2,1)="" "" otherwise "${abs.evaluateAt(this.cellNumericValue(2,1))}"

```

I like the simpleFunction better, but I played with another way ([link](https://cl.desmos.com/t/rounding-truncating/1035/5)) here:

```auto
cellContent(1,2): when this.cellContent(1,1)="" "" otherwise "${numericValue("\\operatorname{abs}(${this.cellNumericValue(1,1)})")}"
cellContent(2,2): when this.cellContent(2,1)="" "" otherwise "${numericValue("\\operatorname{abs}(${this.cellNumericValue(2,1)})")}"

```

---

<div class="post-metadata">

**Author:** ![Svetlana\_Yushmanova](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/svetlana_yushmanova/32/479_2.png) [@Svetlana\_Yushmanova](https://cl.desmos.com/u/Svetlana_Yushmanova)\
**Post date:** [January 4, 2021, 10:58am UTC](https://cl.desmos.com/t/evaluate-function/2270/11 "2021-01-04T10:58:02Z")

</div>

your original syntax did work, so thank you very much indeed
