# Formula from random values

Hi,

I’m new to writing CL, but I had this function that needs to essentially do this:
bcd - ((d-2a)0.5(d-2a)0.53.142*.5*b)

Each of those variables is assigned a random value from a previous screen. I wrote it like this, but it’s not getting the correct value. Is there anything wrong with the syntax? I know there is probably a better way to write it, but this is all I can figure out. Thanks!

simpleFunction(“f\left(x\right)={input34.script.b}*{input34.script.c}{input34.script.d}-({input34.script.d}-{2}*{input34.script.a}{0.5})^2*{3.142}*{0.5}*{input34.script.b}”)

First, it’ll be easier to simplify to (I assume 3.142 is pi):
b *c* d - (0.125*\\pi*b(d-2a)^2)

Any variable called needs to be surrounded by ${ } . It also might make things easier (at least to read/type the code) to create a variable for each first, then create the function. (The “f(x)=” is unnecessary as well.) a=input34.script.a b=input34.script.b c=input34.script.c d=input34.script.d f=simpleFunction(${b}*${c}*${d}-(0.125*\\pi*${b}(${d}-2\${a})^2)


Thanks. That sounds like an easier way to set it up. I’ll give it a try!

And actually since there isn’t a variable x, you could use numericValue instead of simpleFunction if you just want the output value. Otherwise, you have to use evaluateAt as well.

And you could avoid the first four variables by doing the calculation within input34 and just calling the variable for the calculation wherever you need it.