Performing calculations within a table

Hi, is there a way to use CL to create a calculated column in a table?

I want students to calculate and enter probabilities in one column and have the table automatically multiply those probabilities by 50 and show the result in the next column.

Many thanks!

This should do the trick, assuming your probabilities are in column 1 and the product should be in column 2. If you need another row, just duplicate the code and change the (1,1) and (1,2) to (2,1) and (2,2), respectively.

cellContent(1,2): when isDefined(this.cellNumericValue(1,1)) "${numericValue("${this.cellNumericValue(1,1)}*50")}" otherwise ""
2 Likes

Thank you that is brilliant!

I wanted to do something similar but instead take the square root of the number in cell(1,1).
I used the same code but wanted instead of multiplying by 50 I tried ^0.5.
I get an error when raising the number to 1/2 (0.5) but it works when square the number (ie ^2). I also tried ^(0.5) and it also gets an error.
Any ideas?

Here is the table I am working with:
https://teacher.desmos.com/activitybuilder/custom/6149276353400c3c18cc42f4

Change the code to the last cell to

1 Like

Thank you StoyanNYC. I was forgetting the \ when I tried sqrt before…

However this formula is only working for 1 digit numbers? I did a test on input of 9 and output is 3, but a test of input 25 gets me output of 7.07.

What am I missing?

P.S. I reformatted the table to only do square root

I edited the script above and now it should work… you need {0.5}, not (0.5)

1 Like

Ahhh. Gotcha. Yes that solved it. Thanks.

Weird how the other script with \sprt didn’t always work, but nice that ^{0.5} did.
Thanks!

Yes… I’d like to figure out why the \sqrt works for x<10 but not after…

1 Like

Great minds think alike! I created a table just like you just posted in the new post. Thanks for doing that!

No problem… I’m really curious. Let’s see if someone has an answer.

We make some assumptions for single digits since \sqrt{}9, for example, doesn’t mean anything. But don’t make that assumption once there are two digits since \sqrt10 could mean \sqrt{1}0 or \sqrt{10}

1 Like

Thank you for responding.

Doesn’t \sqrt${this.cellNumericValue(1,1)} imply that the calculation is supposed to include the entire number in cell (1,1) under the square root?

Not necessarily. What you’re doing there is interpolating the numericValue as part of a string with \sqrt, and then performing an evaluation on that string. If you want to inject a numeric value directly, use simpleFunction

simpleFunction("\sqrt{x}").evaluateAt(cellNumericValue)

(Simplified for generalization and using “” for formatting here)

This also makes it a bit easier to perform the operation repeatedly. You can assign the function to a variable and then call on the variable over and over

Sqrt = simpleFunction("\sqrt{x}")

Row1=Sqrt.evaluateAt(this.cellNumericValue(1,1))
Row2=Sqrt.evaluateAt(this.cellNumericValue(2,1))
Row3=Sqrt.evaluateAt(this.cellNumericValue(3,1))

1 Like

Or keeping with your original format:

\sqrt{ ${this.cellNumericValue(1,1)} }
1 Like

Ah that is perfect. Of course, now that you say it, it is elegant. Thank you.

Yes I see… the placement of $ matters in what assumption is being made. Thank you for this.