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.Tue, 23 Jun 2020 01:37:13 +0200How to solve nonlinear equation having floating values?https://ask.sagemath.org/question/52139/how-to-solve-nonlinear-equation-having-floating-values/I'm trying to solve equation which simplifies to this form:
`a^x = b`
eg.
`solve([(123)^y==(234234)],y)`
which returns `[y == log(234234)/log(123)]`
but `solve([(123.123)^y==(234234.123)],y)` (having floating point constants)
returns
[123123^y == 234234123*1000^(y - 1)]
How do I get it to return the answer in terms of log.Mon, 22 Jun 2020 04:02:26 +0200https://ask.sagemath.org/question/52139/how-to-solve-nonlinear-equation-having-floating-values/Answer by Juanjo for <p>I'm trying to solve equation which simplifies to this form:</p>
<p><code>a^x = b</code></p>
<p>eg.
<code>solve([(123)^y==(234234)],y)</code></p>
<p>which returns <code>[y == log(234234)/log(123)]</code></p>
<p>but <code>solve([(123.123)^y==(234234.123)],y)</code> (having floating point constants)
returns </p>
<pre><code>[123123^y == 234234123*1000^(y - 1)]
</code></pre>
<p>How do I get it to return the answer in terms of log.</p>
https://ask.sagemath.org/question/52139/how-to-solve-nonlinear-equation-having-floating-values/?answer=52163#post-id-52163You can convert the floating point constants to rationals and use Sympy:
sage: y = var("y")
sage: a = 123.123
sage: b = 234234.123
sage: solve(QQ(a)^y==QQ(b), y, algorithm="sympy")
[y == (log(234234123) - 3*log(10))/(log(123123) - 3*log(10))]
It seems that Sympy can also provide a numerical solution if its domain is restricted:
sage: solve(a^y==b, y, algorithm="sympy", domain="real")
[y == 2.56879371128374]
Tue, 23 Jun 2020 01:37:13 +0200https://ask.sagemath.org/question/52139/how-to-solve-nonlinear-equation-having-floating-values/?answer=52163#post-id-52163