|
From: Eduardo O. <edu...@gm...> - 2022-01-04 02:40:57
|
Thanks, Michael and Richard!
Just as a curiosity - and for the sake of completeness, and because
it's fun - let me explain why I needed this. I teach Calculus 2, and
all the books that I know say that to integrate polynomials of
"sin(k*x)"s and "cos(k*x)"s you have to apply some standard
trigonometric identities as many times as needed, and hope that at
some point you get something that you know how to integrate. I don't
like that method, so I teach an alternative... I was trying to write a
program that performs the alternative method that I like, and I was
able to write something - ugly, but it was my first program in Maxima!
- that gave the right results except for the "constant" part... and
then I discovered that I can replace it by this one-line program:
myexptrick(f) := expand(demoivre(expand(exponentialize(f))));
So, in
f : sin(x)^4 * cos(x)^2;
g : expand(exponentialize(f));
ratcoeff(g, exp(%i*x), 0);
v : subst([x=-%i*log(z)], g);
vt : taylor(v, z, 0, 10);
coeff(vt, z, 0);
myexptrick(f) := expand(demoivre(expand(exponentialize(f))));
h : myexptrick(f);
plot2d([f, h], [x, 0, 2*%pi]);
the line with "ratcoeff" implements Michael's suggestion, and the
lines with "v" and "vt" implement Richard's suggestion. The lines with
"myexptrick" convert the function f to the normal form that I was
looking for, and the "plot2d" is a good way to give to students some
evidence that at least in this case "myexptrick" returns an output
that is equivalent to its input...
Cheers and thanks again =),
Eduardo Ochs
http://angg.twu.net/#eev
http://angg.twu.net/eev-maxima.html
On Sun, 2 Jan 2022 at 17:18, Richard Fateman <fa...@gm...> wrote:
> In some sense this is not the constant coefficient. If z = exp(%i*x) then
> the expression is
>
> v: (z^18-2*z^16-z^14+4*z^12-z^10-2*z^8+z^6)/(64*z^12)
>
> note the denominator.
>
> If you are seeking the term(s) in the expression that do not depend on x
> [or z] , consider
>
> taylor(v,z,0, 10);
>
> which is (I added spaces here for emphasis ...)
>
> 1/(64*z^6)-1/(32*z^4)-1/(64*z^2) + 1/16 -
> z^2/64-z^4/32+z^6/64+...
>
> RJF
>
>
>
>
>
>
> On Sun, Jan 2, 2022 at 8:47 AM Michel Talon <ta...@lp...>
> wrote:
>
>>
>> Le 02/01/2022 à 17:34, Eduardo Ochs a écrit :
>> > but I don't know how to extract the constant term - i.e., how to
>> > obtain the coefficient of exp(0*%i*x)... these things don't work:
>> >
>> > coeff(g, exp(0*%i*x));
>> > coeff(g, x, 0);
>> > coeff(g, 1);
>>
>> (%i5) ratcoeff(g,exp(%i*x),0);
>> 1
>> (%o5) --
>> 16
>>
>>
>> --
>> Michel Talon
>>
>>
>>
>> _______________________________________________
>> Maxima-discuss mailing list
>> Max...@li...
>> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>>
> _______________________________________________
> Maxima-discuss mailing list
> Max...@li...
> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>
|