Ask Your Question

Symbolic calculus of extrema

asked 2018-01-02 12:13:50 +0200

dg.aragones gravatar image

updated 2018-01-03 17:09:21 +0200


Is there any way in Sagemath to find symbolically the local extrema of a given function?

Thanks for your answers!

EDIT: As an example one may be interested in the extrema of the following differentiable function:

z(x)=(cosh(-1/2*K*l+K*x)-cosh(1/2*K*l))/K; #Given function
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2018-01-03 21:34:30 +0200

tmonteil gravatar image

updated 2018-01-03 21:36:36 +0200

Given the example, it is pretty easy:

sage: K=var('K');
....: l=var('l');
....: x=var('x');
....: z(x)=(cosh(-1/2*K*l+K*x)-cosh(1/2*K*l))/K;

The derivative of z (with respect to the variable x) is:

sage: diff(z(x),x)
sinh(-1/2*K*l + K*x)

Since the only zeros of the sinh function is zero, solving $z'(x)=0$ is equivalent to solving $-1/2Kl + K*x=0$:

sage: solve(-1/2*K*l + K*x == 0, x)
[x == 1/2*l]

EDIT Actually Sage knows about sinh:

sage: solve(diff(z(x),x)==0,x)
[x == 1/2*l]

So, if there is an extrema, it can only be at $x=l/2$, but it is not sure yet.

Now, since sinh changes its sign at 0, and since -1/2*K*l + K*x is affine, z' changes its sign at l/2 (when K is nonzero), hence the point $x=l/2$ is an extrema (hence, the only one). The nature of the extrema depends on the sign of K.

You can check with different values of K and l, e.g.:

sage: z.subs(K=2,l=2).plot([-1,2])
sage: z.subs(K=-2,l=2).plot([-1,2])
sage: z.subs(K=1,l=3).plot([-1,3])
sage: z.subs(K=-1,l=3).plot([-1,3])
edit flag offensive delete link more

answered 2018-01-02 16:30:18 +0200

dan_fulea gravatar image

Please give the given function.

(Or describe somehow the class of functions which are relevant for the intended application. Is e.g. the function a polynomial / a rational function?)

If it is differentiable, then sage can calculate the first relevant derivatives. The human hand can finally simply solve the puzzle.

For instance:

sage: f(x) = x^3 + 6*x^2 + 10*x + 6
sage: extList = diff(f(x),x).roots( ring=AA, multiplicities=0 )
sage: extList
[-2.816496580927726?, -1.183503419072274?]
sage: for ext in extList:
....:     print """x=%s f(x)=%s f"(x)=%s""" % (ext, f(ext), diff(f(x),x,2)(x=ext))
x=-2.816496580927726? f(x)=3.088662107903635? f"(x)=-4.898979485566356?
x=-1.183503419072274? f(x)=0.911337892096366? f"(x)=4.898979485566356?
edit flag offensive delete link more


+1 for the requesting a concrete example !

tmonteil gravatar imagetmonteil ( 2018-01-02 16:42:23 +0200 )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


Asked: 2018-01-02 12:13:50 +0200

Seen: 1,544 times

Last updated: Jan 03 '18