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.Thu, 22 Oct 2020 17:04:00 +0200How do I get the exact x value that find-root usedhttps://ask.sagemath.org/question/54002/how-do-i-get-the-exact-x-value-that-find-root-used/I was using this simple algorithm to find roots, but it occurred to me that I want the exact x-value at the point where find_root locates the yval. Except I'm only using the last xval. I'm unclear how I could get the actual xval that find_root used when finding the zero.
roots=[]
for xval in [-10..5,step=.1]:
try:
yval=find_root(cos(x)-exp(x),xval,xval+.1)
roots.append((xval,0))
except:
passThu, 22 Oct 2020 03:17:45 +0200https://ask.sagemath.org/question/54002/how-do-i-get-the-exact-x-value-that-find-root-used/Answer by Emmanuel Charpentier for <p>I was using this simple algorithm to find roots, but it occurred to me that I want the exact x-value at the point where find_root locates the yval. Except I'm only using the last xval. I'm unclear how I could get the actual xval that find_root used when finding the zero.</p>
<pre><code>roots=[]
for xval in [-10..5,step=.1]:
try:
yval=find_root(cos(x)-exp(x),xval,xval+.1)
roots.append((xval,0))
except:
pass
</code></pre>
https://ask.sagemath.org/question/54002/how-do-i-get-the-exact-x-value-that-find-root-used/?answer=54006#post-id-54006The answer(s) of interest is(are) the `yval` values, the `xval` values are the bounds of the search interval. If those are the bounds you are interested in, you may try :
roots=[]
for xval in [-10..5, step=.1]:
try;
yval = find_root(cos(x)-exp(x), xval, xval+.1
root.append((xva, yval, xval+.1))
except:
pass
which gives you a list of solution bracketed by the search bounds leading to them, but I have trouble seeing the point...Thu, 22 Oct 2020 17:04:00 +0200https://ask.sagemath.org/question/54002/how-do-i-get-the-exact-x-value-that-find-root-used/?answer=54006#post-id-54006