Ask Your Question
0

how do I find multiple inflection points?

asked 2020-10-24 02:55:56 +0100

cybervigilante gravatar image

updated 2020-10-24 02:57:01 +0100

I know how to find multiple zeros by repeating find_root over an interval. But how do I find multiple inflection points? Sin has an infinite number but like find_root I'd like to just find them over various intervals. However solve(diff(f)==0,x) doesn't have an option for choosing an interval.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-10-24 22:38:33 +0100

Emmanuel Charpentier gravatar image

I suppose this is not homework. If it is, you'd better try to solve it yourself, peeking this answer only for confirmation, unless you want to miss the point of the homework.

The difficulty isn't to find one solution, but to find them all. In some cases, solve might be able to give them an explicit form. Not here.

find_root will give you one real root in this interval if such one exists. To find the others, you might try searching them in the subintervals defined by this root (with a slight restriction to avoid finding the same root repetitively). However, such a recursive computation should be limited in avoid to (try to) return an infinite number of solutions. Hence the proposal :

 def find_roots(f, a, b, depth=10, epsilon=1e-10):
    def find1(f, a, b, **kwdargs):
        try:
            r =find_root(f, a, b)
            return r
        except RuntimeError:
            return None
    if a > b: a, b = b, a
    r = find1(f, a, b)
    if r is None: return set([])
    if depth == 0 : return set([r])
    a1 = a + (r - a) * epsilon
    b1 = r - (r - a) * epsilon
    a2 = r + (b - r) * epsilon
    b2 = b - (b - r) * epsilon
    R1 = find_roots(f, a1, b1, depth=depth-1, epsilon=epsilon)
    R2 = find_roots(f, a2, b2, depth=depth-1, epsilon=epsilon)
    return set([r]).union(R1).union(R2)

[ Handling and passing the optional arguments to find_root is left as an exercise to the reader...]

Sol=find_roots((x^2*cos(2*x)).diff(x,2),-10,10) ; Sol
{-8.75241852237047,
 -7.205215809879128,
 -5.66982003470027,
 -4.156992355472504,
 -2.692864827014006,
 -1.3444837495903466,
 -0.299870710513912,
 0.299870710513912,
 1.3444837495903472,
 2.692864827014006,
 4.156992355472463,
 5.669820034700045,
 7.205215809879129,
 8.752418522370563}

This proposal of fourteen roots is consistent with the graphical representation :

sage: (x^2*cos(2*x)).diff(x,2).plot((-10,10), ymin=-5, ymax=5)

However, if this answer is numerically satisfying, it is not a proof, which should be searched by other (formal) means.

The depth parameter has effects varying as a function of the implementation of find_root, which does not explicitly documents its algorithm. FWIW, the default depth=10 allows find_roots to return 63 of the (countable) infinity of roots of $\sin{\frac{1}{x}}$ between 0 and 1:

sage: len(find_roots(sin(1/x),0,1))
63

HTH,

edit flag offensive delete link more

Comments

I'm 71 so it's not homework unless I'm a real late starter ๐Ÿ˜€ And I was unclear. I'm not interested in roots, but in the points where the derivative is zero, which I called "inflection points." Maybe they don't use that term anymore. Been fifty years since college.

cybervigilante gravatar imagecybervigilante ( 2020-10-25 06:00:32 +0100 )edit

Please read my answer, instead of skimming it : I have searched the roots of (x^2*cos(2*x)).diff(x,2), i. e. the points where the second derivative of $x^2\cos{2x}$ is null, i. e. the inflection points of $x^2\cos{2x}$.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2020-10-25 09:28:57 +0100 )edit
0

answered 2020-10-24 14:57:01 +0100

tmonteil gravatar image

updated 2020-10-24 14:57:10 +0100

Note that diff(f) is also a symbolic function, so you can use find_root on it as well, and specify an interval, e.g.

find_root(diff(f), 0, 1)
edit flag offensive delete link more

Comments

Ah, that clarifies it. I just wanted to find the xval where a more complicated function changes direction in particular ranges that I can iterate over: find_root(diff((x^2)*cos(2*x)),-5,-2) then results in -3.2891668663611693, which corresponds with its graph., that I put in above to clarify. And the other points are easy to find with a loop. Well, not all them, of course, being infinite ๐Ÿ˜€ I was just used to thinking of find_root to find zeros on the graph, rather than zeros of derivatives.

cybervigilante gravatar imagecybervigilante ( 2020-10-25 12:53:05 +0100 )edit

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: 2020-10-24 02:55:56 +0100

Seen: 535 times

Last updated: Oct 24 '20