#8501: find_root evaluates by plugging an equation into the function
-------------------------+--------------------------------------------------
   Reporter:  jason      |       Owner:  jkantor   
       Type:  defect     |      Status:  new       
   Priority:  major      |   Milestone:  sage-4.3.4
  Component:  numerical  |    Keywords:            
     Author:             |    Upstream:  N/A       
   Reviewer:             |      Merged:            
Work_issues:             |  
-------------------------+--------------------------------------------------
 With 4.3.3:
 {{{
 sage: f1=0.6*x
 sage: f2=0.045*x^2 - 1.44*x + 8.64
 sage: def k(x):
 ...       print x
 ...       if 5<=x<=8:
 ...           return f1(x=x)
 ...       elif 8<=x<=13:
 ...           return f2(x=x)
 ...       else:
 ...           raise ValueError, "Called with impossible value: %s"%x
 ...
 sage: find_root(lambda x:k(x)-55,5,10)
 5.0
 10.0
 6.90983005625
 8.09016994375
 6.1803398875
 6.63093253165711 == 6.68257664471270
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "_sage_input_198.py", line 9, in <module>
     exec compile(ur'open("___code___.py","w").write("# -*- coding: utf-8
 -*-\n" +
 
_support_.preparse_worksheet_cell(base64.b64decode("ZmluZF9yb290KGxhbWJkYSB4OmsoeCktNTUsNSwxMCk="),globals())+"\n");
 execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single')
   File "", line 1, in <module>

   File "/tmp/tmp1LUqkk/___code___.py", line 3, in <module>
     exec compile(ur'find_root(lambda x:k(x)-_sage_const_55 ,_sage_const_5
 ,_sage_const_10 )' + '\n', '', 'single')
   File "", line 1, in <module>

   File "/home/grout/sage/local/lib/python2.6/site-
 packages/sage/numerical/optimize.py", line 92, in find_root
     val, s = find_maximum_on_interval(f, a, b)
   File "/home/grout/sage/local/lib/python2.6/site-
 packages/sage/numerical/optimize.py", line 122, in
 find_maximum_on_interval
     minval, x = find_minimum_on_interval(lambda z: -f(z), a=a, b=b,
 tol=tol, maxfun=maxfun)
   File "/home/grout/sage/local/lib/python2.6/site-
 packages/sage/numerical/optimize.py", line 181, in
 find_minimum_on_interval
     xmin, fval, iter, funcalls = scipy.optimize.fminbound(f, a, b,
 full_output=1, xtol=tol, maxfun=maxfun)
   File "/home/grout/sage/local/lib/python2.6/site-
 packages/scipy/optimize/optimize.py", line 1256, in fminbound
     fu = func(x,*args)
   File "/home/grout/sage/local/lib/python2.6/site-
 packages/sage/numerical/optimize.py", line 122, in <lambda>
     minval, x = find_minimum_on_interval(lambda z: -f(z), a=a, b=b,
 tol=tol, maxfun=maxfun)
   File "", line 1, in <lambda>

   File "/tmp/tmpzDC3MH/___code___.py", line 12, in k
     raise ValueError, "Called with impossible value: %s"%x
 ValueError: Called with impossible value: 6.63093253165711 ==
 6.68257664471270
 }}}

 Note that the last evaluation was a symbolic equation, something ==
 something.  That of course breaks the function.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8501>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to