Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
The equation has three real roots between and . Make 61 equally spaced numbers from to , find the places where the sign of changes, and print the three brackets. Then use brentq from SciPy on each bracket to find the roots.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Use np.sign and compare each value with the next one, as in the lesson. Each change of sign is a bracket. Then brentq finds the root inside it.
Check. The values at and are and , a change of sign. In the same way, the signs change between 0.3 and 0.4, and between 1.5 and 1.6. A cubic has at most three roots, so these are all of them. Put the middle root back: .
Answer: the brackets are , and , and the roots are , and .
Log in to join the discussion.
Loading…