Ask Your Question
0

Programming a function which is able to display Maximum or Minimum of an 1-dimensional function

asked 2016-08-05 17:58:58 +0100

Soul gravatar image

updated 2016-08-05 23:21:55 +0100

tmonteil gravatar image

I had to program a function today which is able to do what i wrote in the title. My attempt in doing this was that:


reset()
forget()
var('x')
Extrempkt= {}

def g(f):
    f=f(x)
    f1(x)=diff(f(x),x); print(f1(x))

    l=len(solve(f1(x)==0,x))
    L=l-1;
    A=[((solve(f1(x)==0,x)[n]).operands()[1]) for n in [0..L]]; print(A)

    if n in [0..L]:
        if f1(A[n]-0.0000001)>f1(A[n]+0.0000001):
            Extrempkt.update({A[n]:"Maximum"})
        if f1(A[n]-0.0000001)<f1(A[n]+0.0000001):
            Extrempkt.update({A[n]:"Minimum"})

    return (Extrempkt)

g((1/9)*x^3-(1/3)*x^2-(8/3)*x+9)

The problem is. My function only puts out my 2nd Extremum. Can you help me?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-08-05 23:42:49 +0100

tmonteil gravatar image

updated 2016-08-05 23:44:19 +0100

Your function is a polynomial of degree 3, so it has no maximum and no minimum over the reals. I am not answering your question, but note that if you want to find a local maximum/minimum, you can do:

sage: f = (1/9)*x^3-(1/3)*x^2-(8/3)*x+9
sage: f.find_local_minimum(-10,10)
(0.11111111111111072, 4.0000000002219425)
sage: f.find_local_maximum(-10,10)
(12.11111111111111, -2.0000000347236591)
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: 2016-08-05 17:58:58 +0100

Seen: 273 times

Last updated: Aug 05 '16