analyse a function in stack/maxima

analyse a function in stack/maxima

by Björn Gerß -
Number of replies: 5

Hello,

I tried to analyse a function, the classic way that a student would do it, in maxima.

The question is to find zeros, maxima, minima, inflection points and saddle points of a 2d function.

Is there a function implemented in maxima to find maxima, minima, inflection points and saddle point? I didn’t find it in the manual or by a simple google search. Or does this need to be done manually step by step?

If I do it step by step, does anyone have a good idea to distinguish maxima and minima from Saddle points?

I tried this:

 

f: the funktion

ff:diff(f,x);

fff:diff(ff,x);

ffff:diff(fff,x);

Nullstellen: set(solve([f=0],[x])); /*zeroes/*

Extremstellen: (set(solve([ff=0],[x]))); /*maxima and minima/*

Wendepunkte: (set(solve([fff=0],[x]))); /*inflection point/*

Sattelpunkte: intersection(Extremstellen,Wendepunkte) /* saddle points/*

if cardinality(Sattelpunkte) = 1 then Extremstellen: disjoin(listify(Sattelpunkte)[1],Extremstellen); /*removing one saddle point form the set of maxima and minima*/

 

But there are two problems remaining:

Disjoin only works for 1 Saddle point. Is there a function that finds the relative complement of B in A for sets I haven´t found yet?

For x^4 this code will find x=0 as a saddle point although it’s a minimum. Is there a nice solution to get around this, without implementing the sign change criterion?

 

Thanks for your help in advance,

Björn


Average of ratings: -
In reply to Björn Gerß

Re: analyse a function in stack/maxima

by Christopher Sangwin -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Björn,

 Good question! In general terms it is impossible to write a function which will do this in the general case, and all this has some interesting maths behind it.

 Two issues to start with.
1. Simple functions have infinitely many stationary points and they don't always occur in nice places, e.g. sin(x^7+x).
2. The nature of stationary points might need more than two differentiations.  E.g. you mention x^4 and I don't know of any code to establish the nature of points automatically. Indeed x^(2n) will require lots of differentiations until you get to a derivative which is non-zero at x=0 to apply the test!

For STACK questions my approach is to start from a known function and reverse engineer the question.  This keeps better control over the questions students see.

Of course, I can understand why you need such a general function if you are accepting expressions from students.

Anything with a "solve" in it will be unreliable in general.

If you develop something please let me know!
Chris



Average of ratings: Useful (1)
In reply to Christopher Sangwin

Re: analyse a function in stack/maxima

by Björn Gerß -
Thanks for the answer, I tried to find a way in maxima.
I did not find a function to make three sets containing either the maxima, minima or saddle points. It seams to be a bad idea for complex functions to work with solve().
In my case it is sufficient and works, to find out the type of one specific point. I implemented it in the way shown underneath. I am not sure yet, if it always works or in which cases it does or does not.

f:-x^4;
xvalue:0;
a: subst(x=xvalue,diff(f,x));
b: if a=0 then limit((1/diff(f,x)),x,xvalue,plus);
c: if a=0 then limit((1/diff(f,x)),x,xvalue,minus) else c:diffnotzero;
j: if (b=inf and c=inf) or (q=minf and p=minf) then saddle
elseif (b=minf and c=inf) then maximum
elseif (b=inf and c=minf) then minimum
elseif (c=diffnotzero) then diffnotzero
else udef;

So, I do not know the limitations – maybe someone has a idea – but it does work for x^(2*n) this time.
It’s maybe not the best coding-style, but solves the question for more functions than before.
I’m happy to hear ideas about it.
In reply to Björn Gerß

Re: analyse a function in stack/maxima

by Björn Gerß -
Hi,
I did change the code I used before to:

isitminmaxorsad(f,xvalue):=block (errcatch (d: notdiffable,
a: subst(x=xvalue,diff(f,x)),
b: if a=0 then limit((1/diff(f,x)),x,xvalue,plus) else diffnotzero,
c: if a=0 then limit((1/diff(f,x)),x,xvalue,minus) else diffnotzero,
d: if (b=inf and c=inf) or (q=minf and p=minf) then saddle
elseif (b=minf and c=inf) then maximum
elseif (b=inf and c=minf) then minimum
elseif (c=diffnotzero) then diffnotzero
else undefined),
return (d));

With this code, the function “isitminmaxorsad(f,x)” becomes available.
This function (“isitminmaxorsad”) takes a first argument “f” which is a function and the second argument “x” which the corresponding x-value.
It checks for the characteristic of the function at the given x-value, for if it is either maxima, minima a saddle point or neither of those.
return values are:
maximum
minimum
diffnotzero
notdiffable
undefined

I would be happy to know if someone finds functions with points that are classified wrong or as undefined even if they are not.
Removable definition gaps are accepted as maxima, minima or saddle point by the code.

Björn
In reply to Björn Gerß

Re: analyse a function in stack/maxima

by Björn Gerß -
Hi,
just some corrections on the code. There was a p and q that was wrong, and stack forbids errcatch. 

So I changed that:

isitminmaxorsad(f,xvalue):=block (
a: subst(x=xvalue,diff(f,x)),
b: if a=0 then limit((1/diff(f,x)),x,xvalue,plus) else diffnotzero,
c: if a=0 then limit((1/diff(f,x)),x,xvalue,minus) else diffnotzero,
d: if (b=inf and c=inf) or (b=minf and c=minf) then saddle
        elseif (b=minf and c=inf) then maximum
            elseif (b=inf and c=minf) then minimum
                elseif (c=diffnotzero) then diffnotzero
                else undefined,
return (d));

Just if someone likes to use it,
Björn
In reply to Björn Gerß

Re: analyse a function in stack/maxima

by Carl Stensfer -
I am a student and I often have problems with function analysis. I'm interested to know if I can use your experience to simplify my tasks.
This is very important for me, because I can rarely turn to someone for help, but I found https://plainmath.net/secondary/calculus-and-analysis/calculus-1 when it was difficult for me to solve equations, I did not understand them , but at that moment no one could explain anything to me. Therefore, this resource can be useful for students who do not understand something.