Ask Your Question

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

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 close merge delete

## 1 Answer

Sort by ยป oldest newest most voted

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)

more

## Your Answer

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

Add Answer

## Stats

Asked: 2016-08-05 17:58:58 +0200

Seen: 225 times

Last updated: Aug 05 '16