sticky problem

1816 days ago by bardg

f(x) = 8*cos(x) 
       
g(x) = 7*sin(2*x) 
       
print "We start with examining the area between 0 and pi" 
       
We start with examining the area between 0 and pi
We start with examining the area between 0 and pi
find_root( f(x) == g(x), 0, pi) 
       
2.5333470746795834
2.5333470746795834
print "Okay, we found a root in [0,pi] equal to that, so we look from zero to that root, and from there to pi." 
       
Okay, we found a root in [0,pi] equal to that, so we look from zero to
that root, and from there to pi.
Okay, we found a root in [0,pi] equal to that, so we look from zero to that root, and from there to pi.
find_root( f(x) == g(x), 0, 2.53334) 
       
1.5707963267948966
1.5707963267948966
n( pi/2 ) 
       
1.57079632679490
1.57079632679490
find_root( f(x) == g(x), 2.53335, pi) 
       
Traceback (click to the left of this block for traceback)
...
RuntimeError: f appears to have no zero on the interval
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_16.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZmluZF9yb290KCBmKHgpID09IGcoeCksIDIuNTMzMzUsIHBpKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpgT6I9s/___code___.py", line 3, in <module>
    exec compile(u'find_root( f(x) == g(x), _sage_const_2p53335 , pi)
  File "", line 1, in <module>
    
  File "/home/sageserver/sage/sage-5.0-stock/local/lib/python2.7/site-packages/sage/numerical/optimize.py", line 72, in find_root
    return f.find_root(a=a,b=b,xtol=xtol,rtol=rtol,maxiter=maxiter,full_output=full_output)
  File "expression.pyx", line 8316, in sage.symbolic.expression.Expression.find_root (sage/symbolic/expression.cpp:31805)
  File "/home/sageserver/sage/sage-5.0-stock/local/lib/python2.7/site-packages/sage/numerical/optimize.py", line 104, in find_root
    raise RuntimeError, "f appears to have no zero on the interval"
RuntimeError: f appears to have no zero on the interval
print "We did not find a root in the second subdivision, but we found one in the first. Now we'll look between 0 and the new root, and between the new root and the old root." 
       
We did not find a root in the second subdivision, but we found one in
the first. Now we'll look between 0 and the new root, and between the
new root and the old root.
We did not find a root in the second subdivision, but we found one in the first. Now we'll look between 0 and the new root, and between the new root and the old root.
find_root( f(x) == g(x), 0, 1.57079) 
       
0.6082455789102097
0.6082455789102097
find_root( f(x) == g(x), 1.57080, 2.53334) 
       
Traceback (click to the left of this block for traceback)
...
RuntimeError: f appears to have no zero on the interval
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_21.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZmluZF9yb290KCBmKHgpID09IGcoeCksIDEuNTcwODAsIDIuNTMzMzQp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpuzSd9D/___code___.py", line 3, in <module>
    exec compile(u'find_root( f(x) == g(x), _sage_const_1p57080 , _sage_const_2p53334 )
  File "", line 1, in <module>
    
  File "/home/sageserver/sage/sage-5.0-stock/local/lib/python2.7/site-packages/sage/numerical/optimize.py", line 72, in find_root
    return f.find_root(a=a,b=b,xtol=xtol,rtol=rtol,maxiter=maxiter,full_output=full_output)
  File "expression.pyx", line 8316, in sage.symbolic.expression.Expression.find_root (sage/symbolic/expression.cpp:31805)
  File "/home/sageserver/sage/sage-5.0-stock/local/lib/python2.7/site-packages/sage/numerical/optimize.py", line 90, in find_root
    raise RuntimeError, "f appears to have no zero on the interval"
RuntimeError: f appears to have no zero on the interval
print "Okay, now we are almost done. We have to check between 0 and 0.608245..." 
       
Okay, now we are almost done. We have to check between 0 and 0.608245...
Okay, now we are almost done. We have to check between 0 and 0.608245...
find_root( f(x) == g(x), 0, 0.608245) 
       
Traceback (click to the left of this block for traceback)
...
RuntimeError: f appears to have no zero on the interval
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_23.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZmluZF9yb290KCBmKHgpID09IGcoeCksIDAsIDAuNjA4MjQ1KQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpevdkmH/___code___.py", line 3, in <module>
    exec compile(u'find_root( f(x) == g(x), _sage_const_0 , _sage_const_0p608245 )
  File "", line 1, in <module>
    
  File "/home/sageserver/sage/sage-5.0-stock/local/lib/python2.7/site-packages/sage/numerical/optimize.py", line 72, in find_root
    return f.find_root(a=a,b=b,xtol=xtol,rtol=rtol,maxiter=maxiter,full_output=full_output)
  File "expression.pyx", line 8316, in sage.symbolic.expression.Expression.find_root (sage/symbolic/expression.cpp:31805)
  File "/home/sageserver/sage/sage-5.0-stock/local/lib/python2.7/site-packages/sage/numerical/optimize.py", line 90, in find_root
    raise RuntimeError, "f appears to have no zero on the interval"
RuntimeError: f appears to have no zero on the interval
print "Now we are done." 
       
Now we are done.
Now we are done.
root1=2.5333470746795834 
       
root2 = 1.57079632679490 
       
root3 = 0.6082455789102097 
       
plot( f(x), -1, pi+1, color='red') + plot( g(x), -1, pi+1, color='blue') + point( (root1, f(root1)), color='green', size=30 ) + point( (root2, f(root2)), color='green', size=30 ) + point( (root3, f(root3)), color='green', size=30 ) 
       
sin(1.5) 
       
0.997494986604054
0.997494986604054
2*cos(0.75)*sin(0.75) 
       
0.997494986604054
0.997494986604054