How to find the maximum and minimum functions using Maxima?

I am trying to find a way to get the maximum and minimum value of a function using Maxima (wxMaxima), but so far I have not found how to do this.

Could you tell me how you would do it?

For example, suppose I have the following code:

f(x) := (3*x)/(x^2 - 2*x + 4); 

And then I draw this function in the range of -10, 10, and I get:

enter image description here

I know that the maximum is 3/2, and the minimum should be -1/2.

+5
source share
4 answers

My advice is to find extreme values โ€‹โ€‹the same way you did it manually: calculate the derivative, solve for the derivative = 0 and replace any values โ€‹โ€‹found back to the original function. For instance:.

 (%i1) f(x) := (3*x)/(x^2 - 2*x + 4); 3 x (%o1) f(x) := ------------ 2 x - 2 x + 4 (%i2) diff (f(x), x); 3 3 x (2 x - 2) (%o2) ------------ - --------------- 2 2 2 x - 2 x + 4 (x - 2 x + 4) (%i3) ratsimp (%); 2 3 x - 12 (%o3) - ----------------------------- 4 3 2 x - 4 x + 12 x - 16 x + 16 (%i4) num (%); 2 (%o4) 12 - 3 x (%i5) solve (%, x); (%o5) [x = - 2, x = 2] (%i6) map (lambda ([e], subst (e, f(x))), %); 1 3 (%o6) [- -, -] 2 2 

If I were careful, I would check that x = -2 and x = 2 are really extreme values, not just inflection points, and I would check that the denominator% o3 is nonzero at x = -2 and x = 2 before trying to estimate f (x) at these points.

+8
source

Use the lbfgs function as follows:

 lbfgs(-f(x), [x], [1.0], 1e-4, [-1,0]); 

The above code gives the position [x = 2] of the maximum function.

0
source

lbfgs finds the minimum value.

The tim code finds the minimum value of -f(x) and, therefore, the maximum value of f(x) . [x] = variable. [1.0] = initial score. [-1,0] = find the maximum value between x = -1 and x = 0 . 1e-4 = epsilon, I think that basically it becomes a level of precision or step value.

0
source

enter image description here

Determine when the derivative increases or decreases

0
source

All Articles