ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 19 Jan 2015 22:22:48 -0600How to pick out the largest root of an equation?http://ask.sagemath.org/question/25568/how-to-pick-out-the-largest-root-of-an-equation/ I tried the following but it didn't work,
p = x^2 - 7*a*x + 5;
a=5;
m = max((p == 0).solve([x]))
PhoenixMon, 19 Jan 2015 22:22:48 -0600http://ask.sagemath.org/question/25568/Trigonometric Equation Solving: Not Terminatinghttp://ask.sagemath.org/question/9898/trigonometric-equation-solving-not-terminating/## The Background
I want to write a script which is able to do the following:
- **INPUT:** **`x`** - A list of triangle items. These items are considered as given.
- **INPUT:** **`y`** - A list of triangle items. We want to know the abstract formulas of these items.
- **OUTPUT:** **`z`** - A list of formulas to calculate the items from `y`
For example:
- **INPUT:** **`x`** - `[alpha, beta]` (considered as given)
- **INPUT:** **`y`** - `[gamma]` (we want to know the formula of `gamma`)
- **OUTPUT:** **`z`** - `[gamma == pi - alpha - beta]`
I want to do that using `sage`'s `solve()`.
## My Problem:
This is a simplified script. It is just able to output formulas for `alpha`, `beta` and `gamma` when `a`, `b` and `c` are considered as given:
rings = RR[('a', 'b', 'c')].gens()[:3] # considered as given
x = dict([(str(rings_), rings_) for rings_ in rings])
varbs = SR.var(['alpha', 'beta', 'gamma']) # looking for `alpha`, `beta` and `gamma`
x.update([(str(varbs_), varbs_) for varbs_ in varbs])
print solve([
#x['a']**2 == x['b']**2 + x['c']**2 - 2*x['b']*x['c']*cos(x['alpha']),
#x['b']**2 == x['a']**2 + x['c']**2 - 2*x['a']*x['c']*cos(x['beta']),
#x['c']**2 == x['a']**2 + x['b']**2 - 2*x['a']*x['b']*cos(x['gamma']),
x['alpha'] == arccos((x['a']**2 - x['b']**2 - x['c']**2) / 2*x['b']*x['c']),
x['beta'] == arccos((x['b']**2 - x['a']**2 - x['c']**2) / 2*x['a']*x['c']),
x['gamma'] == arccos((x['c']**2 - x['a']**2 - x['b']**2) / 2*x['a']*x['b']),
#pi == x['alpha'] + x['beta'] + x['gamma'],
], [
x['alpha'],
x['beta'],
x['gamma'],
])
This script is working correctly and outputs:
[
[alpha == pi - arccos(-0.5*a^2*b*c + 0.5*b^3*c + 0.5*b*c^3), beta == pi - arccos(0.5*a^3*c - 0.5*a*b^2*c + 0.5*a*c^3), gamma == arccos(-0.5*a^3*b - 0.5*a*b^3 + 0.5*a*b*c^2)]
]
I wanted to extend `solve()`'s knowledge base in order to be able to solve more complicated problems later on. But when I tried to uncomment the `#` lines and ran the script again, `solve()` didn't terminate any more.
## My Question:
* Why doesn't `solve()` terminate when I uncomment the `#` lines?
* How can I get `sage` to terminate? Or: How can I work around this problem?
Thanks - if anything's unclear, please leave a comment concerning that.fdj815Sun, 10 Mar 2013 03:56:09 -0500http://ask.sagemath.org/question/9898/