ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 15 Oct 2012 20:24:20 -0500Finding solution to nonlinear equations numerically in a rangehttp://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 12:15:30 -0500http://ask.sagemath.org/question/9430/finding-solution-to-nonlinear-equations-numerically-in-a-range/Answer 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>
http://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]Mon, 15 Oct 2012 20:24:20 -0500http://ask.sagemath.org/question/9430/finding-solution-to-nonlinear-equations-numerically-in-a-range/?answer=14154#post-id-14154Answer 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>
http://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=_)Mon, 15 Oct 2012 18:33:04 -0500http://ask.sagemath.org/question/9430/finding-solution-to-nonlinear-equations-numerically-in-a-range/?answer=14153#post-id-14153