we can type in SAGE:

> solve(3*x^2 + 16*x - 28 == 0, x)

[x == -2/3*sqrt(37) - 8/3, x == 2/3*sqrt(37) - 8/3]

> round(-2/3*sqrt(37) - 8/3, 3)

-6.722> round(2/3*sqrt(37) - 8/3, 3)

1.389

Easy peasy!

**Another example**

In the Little Book of R for Biomedical Statistics I have an equation:

n = numerator/denominator

where

numerator = 2 * ((qalpha + qgamma)^2) * pi0 * (1 - p0)

denominator = (piT - piC)^2

pi0 = (piT + piC)/2

Let's use SAGE to rearrange the equation in terms of piT: (Here I type 'a' for qalpha, 'g' for qgamma, 'T' for piT and 'C' for piC):

> a, g, T, C, n = var('a g T C n')

> numerator = 2 * ((a+g)^2) * ((T+C)/2) * (1 - ((T+C)/2))

> denominator = (T - C)^2

> solve(n == numerator/denominator, T)

## No comments:

Post a Comment