Newbie question: diff,ratsimp,factor



On Tue, Feb 13, 2007 at 07:00:02AM -0000, Scott Ballantyne wrote:
> Experimenting with maxima for the first time, I tried to compute the
> derivative of (%e^x-%e^(-x))/(%e^x+%e^(-x)), which I believe should
> be: 4/(e^x+e^-x)^2.
> 
> Maxima gives 1 - (e^x-e^(-x))^2/(e^x+e^(-x))^2
> 
> which is of course fine, but when I try to simplify this (I used
> ratsimp(%) and then factor(%)), maxima delivers
> 
> 4e^(2x)/(e^(2x)+1)^2
> 
> Perhaps this is correct, although it doesn't look like it at first
> blush.
> 
> What is the best way to get the simple form of this expression?
> 
> Thanks and many apologies if this is a common question.

By now you've seen a whole host of responses. Here is another take on
this issue.

In maxima, there are sometimes "canonical" forms for expressions, such
as the "canonical rational expression" (CRE) that is formed by the
function "rat". In some sense this is the simplest form for those
types of expressions, though it's not necessarily true in a sense that
a human cares about. However in other cases, there is no notion of a
"most simple" expression. Often users have an idea of what they want
from maxima, and instead they get something else. Maxima provides a
set of tools to allow you to manipulate expressions. Occasionally
you'll get some result which looks complicated but is in fact
relatively simple when manipulated into the form you expect. Stavros
has given you an example of going the other way (complexifying a
simple expression).

with your expression 4e^(2x)/(e^(2x)+1)^2 you might decide to
manipulate the expression into a form you like better. 

you can pick apart the numerator, and denominator using "num" and
"denom" and you can multiply by factors using * or "multthru". You can
use "subst" to replace expressions, for example

expr:4*%e^(2*x)/(%e^(2*x)+1)^2;
subst(y^2,%e^(2*x),expr);
[num(%)/y^2, denom(%)/y^2];
subst((y+1/y)^2,(y^2+1)^2/y^2,%);
first(%)/second(%);
subst(%e^x,y,%);

However, to do this, you've been forced to "do the math" yourself. In
particular the fourth line requires you to figure out that
(y^2+1)^2/y^2 = ((y^2+1)/y)^2

Nevertheless this is frequently the way that one works with
maxima. It's basically a tool to let you manipulate expressions
without transcription errors, and to carry out complicated tasks
automatically. But it isn't going to read your mind. :-)



-- 
Daniel Lakeland
dlakelan at street-artists.org
http://www.street-artists.org/~dlakelan