Increment command

my math formula
P( X= x) = n_cx * p^x *q ^(n-x)

P( X =x ) = {=(combination(n,x))(p^x)((1-p)^(n-x))}

P( X < 5)

i want to write code in text blaze for P( X <5) are x's are additive like P(X=0) + P(X=1) +P(X=2)+P( X=3)+P (X=4)

i need to help to increment command and output like this P(X=0) + P(X=1) +P(X=2)+P( X=3)+P (X=4) upto X (code)

what command function need

any one help me please

Hi Sekhar.

You can use {repeat} and {if} commands with the seq function together as follows:

{formtext: name=number; default=3}

{repeat: for x in seq(0, number - 1)} P (X={=x}) {if: x < number - 1}+{endif}{endrepeat}

Hope that helped you. :slight_smile:

Here is a small example:

{factorial=(n)->reduce(seq(1,n), 1, (a, v)->a*v) if n > 0 else 1}
{combination=(n, r)->factorial(n)/factorial(r)/factorial(n-r)}

{n=4}
{x=3}
{p=0.5}
{plist=map(seq(0,x - 1),(i)->combination(n,i)*p^i*(1-p)^(n-i))}
{=sum(plist)}

You can find information about factorial and combination functions below:

Also consider using formtext command to make calculations interactive to your input.