Ask Your Question
1

Find all roots of an equation

asked 2018-01-23 21:56:04 -0500

happys5 gravatar image

Hello,

I have tried the following: used solve() by itself and with "to_solve_poly=True", imported simpy, tried find_root, and tried eq.roots(). find_root() gave me one root when there are several between 0,11.

How can I solve for all the roots in a range. Here is my final code.

  var('PI')

PI = 2*asin(1.0)
eq = exp(-x)-sin(0.5*PI*x)==0
show(plot(exp(-x)-sin(0.5*PI*x), x, xmin = -10, xmax = 10, ymin =-10, ymax=10))
eq.find_root(0, 11)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-01-24 07:09:31 -0500

tmonteil gravatar image

updated 2018-01-24 16:15:03 -0500

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]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-01-23 21:56:04 -0500

Seen: 76 times

Last updated: Jan 24