Opened 12 years ago

Last modified 8 years ago

#8501 new defect

find_root evaluates by plugging an equation into the function

Reported by: jason Owned by: jkantor
Priority: major Milestone: sage-6.4
Component: numerical Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

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.

Change History (4)

comment:1 Changed 9 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:2 Changed 9 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:3 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:4 Changed 8 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4
Note: See TracTickets for help on using tickets.