ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 05 Sep 2020 19:23:31 +0200Finding solution of expression with fractional powerhttps://ask.sagemath.org/question/53299/finding-solution-of-expression-with-fractional-power/I'm trying to solve this equation
$ 3(2.2+(\frac{64}{r})^{(1/3)})= 4(2.2+(\frac{128}{r-1})^{(1/4)})$ using solve function
I want to obtain the numerical solution
**but when i use `sol[0].n(30)`**
**TypeError:** cannot evaluate symbolic expression numerically
**when i try to `find_root(0,1,r)`**
**ValueError:** negative number to a fractional power not real
How to find the solution of this expression ?
Fri, 04 Sep 2020 11:18:45 +0200https://ask.sagemath.org/question/53299/finding-solution-of-expression-with-fractional-power/Answer by dan_fulea for <p>I'm trying to solve this equation</p>
<p>$ 3(2.2+(\frac{64}{r})^{(1/3)})= 4(2.2+(\frac{128}{r-1})^{(1/4)})$ using solve function</p>
<p>I want to obtain the numerical solution </p>
<p><strong>but when i use <code>sol[0].n(30)</code></strong></p>
<p><strong>TypeError:</strong> cannot evaluate symbolic expression numerically</p>
<p><strong>when i try to <code>find_root(0,1,r)</code></strong></p>
<p><strong>ValueError:</strong> negative number to a fractional power not real</p>
<p>How to find the solution of this expression ?</p>
https://ask.sagemath.org/question/53299/finding-solution-of-expression-with-fractional-power/?answer=53308#post-id-53308We do not know what is `sol`, but i suppose it is the following...
sage: var('r');
sage: eq = 3*(2.2 + (64/r)^(1/3)) == 4*(2.2 + (128/(r-1))^(1/4))
sage: sol = solve(eq, r)
sage: sol
[r^(1/3) == 60*(r - 1)^(1/4)/(40*8^(1/4) + 11*(r - 1)^(1/4))]
It is clear that we cannot ask for the numerical value of `sol[0]`.
----------
Instead, we could help sage deliver the needed value. We just substitute
$$
r = R^3
$$
and rewrite the given equation in the form:
$$
\frac 34\left(\frac{22}{10} +\frac 4R\right)-\frac {22}{10} = \left(\frac {128}{R^3-1}\right)^{1/4}\ .
$$
Rising both sides to the fourth power leads to a polynomial equation, which we can solve.
We obtain one value of $R$, introduced by taking the fourth power. But it leads to no solution in $r$.
Try a plot of the difference to see there is no solution.
If there is some typo, then fix it, find an interval where the difference function changes the sign, then use `gp`-solve. (Inside pari or inside sage.)Sat, 05 Sep 2020 04:42:14 +0200https://ask.sagemath.org/question/53299/finding-solution-of-expression-with-fractional-power/?answer=53308#post-id-53308Answer by Emmanuel Charpentier for <p>I'm trying to solve this equation</p>
<p>$ 3(2.2+(\frac{64}{r})^{(1/3)})= 4(2.2+(\frac{128}{r-1})^{(1/4)})$ using solve function</p>
<p>I want to obtain the numerical solution </p>
<p><strong>but when i use <code>sol[0].n(30)</code></strong></p>
<p><strong>TypeError:</strong> cannot evaluate symbolic expression numerically</p>
<p><strong>when i try to <code>find_root(0,1,r)</code></strong></p>
<p><strong>ValueError:</strong> negative number to a fractional power not real</p>
<p>How to find the solution of this expression ?</p>
https://ask.sagemath.org/question/53299/finding-solution-of-expression-with-fractional-power/?answer=53322#post-id-53322Ahem... `solve` suggests numerical *approximate* solutions :
sage: SN=solve(Eq, r, to_poly_solve=True) ; Sn
[r == (-0.08510234586942406 - 0.5483016107521035*I),
r == (-0.08510234586942406 + 0.5483016107521035*I)]
sage: print([(Eq.lhs()-Eq.rhs()).subs(s).n() for s in SN])
[1.77635683940025e-15*I, -1.77635683940025e-15*I]
Not *that* far of the target... But indeed :
sage: print([(Eq.lhs()-Eq.rhs()).subs(s).is_zero() for s in SN])
[False, False]
Let's hunt for *exact* solutions, if any... Start by rewriting the equation, as judiciously suggested by `dan_fulea` :
Eq=3*((11/5)+(64/r)^(1/3))==4*(11/5+(128/(r-1))^(1/4)) ; print(Eq)
$$\frac{12}{r^{\frac{1}{3}}} + \frac{33}{5} = \frac{8 \cdot 8^{\frac{1}{4}}}{{\left(r - 1\right)}^{\frac{1}{4}}} + \frac{44}{5}$$
Work on this a bit :
E2=Eq.subs([r==R^3,(R^3)^(-1/3)==R^-1])-44/5 ; print(E2)
(One will note the awkward internal representation of powers in fractions...)
$$\frac{12}{R} - \frac{11}{5} = \frac{8 \cdot 8^{\frac{1}{4}}}{{\left(R^{3} - 1\right)}^{\frac{1}{4}}}$$
We eliminate the fractional powers by elevating both hands at the fourth power (thus potentially introducing spurious solutions...) :
E3=(E2^-4).factor()
$$\frac{625 \\, R^{4}}{{\left(11 \\, R - 60\right)}^{4}} = \frac{1}{32768} \\, {\left(R^{2} + R + 1\right)} {\left(R - 1\right)}$$
This equation is utimately the equation of a rational fraction to zero. Its roots are therefore the roots of its denominator, provided that the denominator is not null in these points :
P=(E3.lhs()-E3.rhs()).factor().numerator()
$$-14641 \\, R^{7} + 319440 \\, R^{6} - 2613600 \\, R^{5} + 29998641 \\, R^{4} - 13279440 \\, R^{3} + 2613600 \\, R^{2} - 9504000 \\, R + 12960000$$
A raincheck doesn't hurt :
sage: P.is_polynomial(R)
True
The roots of this polynomial are potential solutions of our original equations...
Sol=P.roots(x=R,ring=QQbar, multiplicities=False)
... provided that they do not nullify the denominator...
Sol=[u for u in Sol if not (E3.lhs()-E3.rhs())(R=u).is_zero()]
... and their cubes are indeed solution of the original equation :
sage: SolR=[u^3 for u in Sol if bool(Eq(r=u^3))] ; SolR
[-0.085102345869424? - 0.548301610752104?*I,
-0.085102345869424? + 0.548301610752104?*I]
Those two solutions are "exact" in the same sense as QQbar is "exact" : there is a way to determinate them with as much as precision as needed, with a upper bound of the difference as small as desired, notwithstanding the absence of a closed-form radical expression...
HTH,
**EDIT :** This result is also found by `Mathematica`, as shown in the following atrocity :
sage: MS=mathematica.Solve(Eq,r);MS
{{r -> Root[-2176782336000000000000 + 6584000661504000000000*#1 -
10160322906612096000000*#1^2 + 21200873670270453024000*#1^3 -
24022442465994700088721*#1^4 - 15246001414346517837*#1^5 -
15216891738794163*#1^6 + 3138428376721*#1^7 & , 4, 0]},
{r -> Root[-2176782336000000000000 + 6584000661504000000000*#1 -
10160322906612096000000*#1^2 + 21200873670270453024000*#1^3 -
24022442465994700088721*#1^4 - 15246001414346517837*#1^5 -
15216891738794163*#1^6 + 3138428376721*#1^7 & , 5, 0]}}
sage: MSR=union(SR(repr(MS[1][1][2][1]).replace("#1","x").replace("&","")).roots(ring=QQbar, multiplicities=False),SR(repr(MS[2][1][2][1]).replace("#1","x").replace("&","")).roots(ring=QQbar, multiplicities=False))
sage: [u for u in MSR if bool(Eq.subs(r=u))]
[-0.0851023458694239? + 0.5483016107521033?*I,
-0.0851023458694239? - 0.5483016107521033?*I]Sat, 05 Sep 2020 19:23:31 +0200https://ask.sagemath.org/question/53299/finding-solution-of-expression-with-fractional-power/?answer=53322#post-id-53322