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, 16 Oct 2012 03:24:20 +0200Finding solution to nonlinear equations numerically in a rangehttps://ask.sagemath.org/question/9430/finding-solution-to-nonlinear-equations-numerically-in-a-range/Hi,
this question is probably quite easy to solve. I've got two nonlinear equations with a solution in the range of (0,1). As described in the sage tutorial I tried the following:
var('p t')
eq2 = p==1 - (1 - (1 - (1 - 0.01)^1036)^20)*(1 - t)^(9)
eq1 = t==(2*(1 - 2*p))/((1 - 2*p)*16 + 15*p(1 - (2*p)^1023))
solns = solve([eq1,eq2],t, solution_dict=True)
[[s[t].n(10)] for s in solns]
Unfortunately this doesn't work. In addition I tried find_root, but failed miserably. Any ideas? Mon, 15 Oct 2012 19:15:30 +0200https://ask.sagemath.org/question/9430/finding-solution-to-nonlinear-equations-numerically-in-a-range/Answer by robert.marik for <p>Hi,</p>
<p>this question is probably quite easy to solve. I've got two nonlinear equations with a solution in the range of (0,1). As described in the sage tutorial I tried the following:</p>
<pre><code>var('p t')
eq2 = p==1 - (1 - (1 - (1 - 0.01)^1036)^20)*(1 - t)^(9)
eq1 = t==(2*(1 - 2*p))/((1 - 2*p)*16 + 15*p(1 - (2*p)^1023))
solns = solve([eq1,eq2],t, solution_dict=True)
[[s[t].n(10)] for s in solns]
</code></pre>
<p>Unfortunately this doesn't work. In addition I tried find_root, but failed miserably. Any ideas? </p>
https://ask.sagemath.org/question/9430/finding-solution-to-nonlinear-equations-numerically-in-a-range/?answer=14153#post-id-14153Hi, the system is special in some sense, I think that you can do the following
var('t')
p=1 - (1 - (1 - (1 - 0.01)^1036)^20)*(1 - t)^(9)
eq1 = t==(2*(1 - 2*p))/((1 - 2*p)*16 + 15*p(1 - (2*p)^1023))
eq1.find_root(-100,100)
and then
p.subs(t=_)Tue, 16 Oct 2012 01:33:04 +0200https://ask.sagemath.org/question/9430/finding-solution-to-nonlinear-equations-numerically-in-a-range/?answer=14153#post-id-14153Answer by achrzesz for <p>Hi,</p>
<p>this question is probably quite easy to solve. I've got two nonlinear equations with a solution in the range of (0,1). As described in the sage tutorial I tried the following:</p>
<pre><code>var('p t')
eq2 = p==1 - (1 - (1 - (1 - 0.01)^1036)^20)*(1 - t)^(9)
eq1 = t==(2*(1 - 2*p))/((1 - 2*p)*16 + 15*p(1 - (2*p)^1023))
solns = solve([eq1,eq2],t, solution_dict=True)
[[s[t].n(10)] for s in solns]
</code></pre>
<p>Unfortunately this doesn't work. In addition I tried find_root, but failed miserably. Any ideas? </p>
https://ask.sagemath.org/question/9430/finding-solution-to-nonlinear-equations-numerically-in-a-range/?answer=14154#post-id-14154You can also use mpmath
from mpmath import *
mp.dps = 30; mp.pretty = True
f1 = lambda t,p:1 - (1 - (1 - (1 - 0.01)**1036)**20)*(1 - t)**(9)-p
f2 = lambda t,p:(2*(1 - 2*p))/((1 - 2*p)*16 + 15*p*(1 - (2*p)**1023))-t
findroot([f1,f2],(1,1))
[2.39470409963011871605945052144e-309]
[ 0.999398871164408619804930822283]Tue, 16 Oct 2012 03:24:20 +0200https://ask.sagemath.org/question/9430/finding-solution-to-nonlinear-equations-numerically-in-a-range/?answer=14154#post-id-14154