1 | initial version |
First, note that you can use the symbolic pi
directly:
sage: eq = exp(-x)-sin(pi*x/2)==0
Then the find_root
method only gives you one root that belongs to the interval. If you want all the roots, you have to localize:
sage: eq.find_root(0,1)
0.4435735341042928
sage: eq.find_root(0,2)
1.9048930509820137
sage: eq.find_root(2,5)
4.011527092383197
sage: eq.find_root(5,7)
5.998419479660961
sage: eq.find_root(7,9)
8.000213516551632
sage: eq.find_root(9,11)
9.999971096671594
Or, more compactly:
sage: [eq.find_root(i,j) for (i,j) in zip(endpoints,endpoints[1:])]
[0.4435735341042928,
1.9048930509820123,
4.011527092383197,
5.998419479660961,
8.000213516551632,
9.999971096671594]
2 | No.2 Revision |
First, note that you can use the symbolic pi
directly:
sage: eq = exp(-x)-sin(pi*x/2)==0
Then the find_root
method only gives you one root that belongs to the interval. If you want all the roots, you have to localize:
sage: eq.find_root(0,1)
0.4435735341042928
sage: eq.find_root(0,2)
1.9048930509820137
sage: eq.find_root(2,5)
4.011527092383197
sage: eq.find_root(5,7)
5.998419479660961
sage: eq.find_root(7,9)
8.000213516551632
sage: eq.find_root(9,11)
9.999971096671594
Or, more compactly:
sage: endpoints = [0,1,2,5,7,9,11]
sage: [eq.find_root(i,j) for (i,j) in zip(endpoints,endpoints[1:])]
[0.4435735341042928,
1.9048930509820123,
4.011527092383197,
5.998419479660961,
8.000213516551632,
9.999971096671594]