Foad S. Farimani
Foad S. Farimani

Reputation: 14036

maxima returns wrong result when using subscripts

I am using WxMaxima for some calculations so I can export the results directly into my LaTeX file. I have some Greek variables with Greek subscripts which are giving me a headache. In the past in Maxima I used to put the subscripts in the bracket []. But I have noticed that the conventional LaTeX syntax of _ also works. Except it doesn't work for greek letters:

enter image description here

So I have to use the brackets one [] when I want to subscript the Greek letters with Greek letters. But it is causing some calculation errors.

For example consider two simple functions:

%epsilon[r](r):=c[1]-c[2]/r^2;
%epsilon[%theta](r):=c[1]+c[2]/r^2;

now if I run:

fullratsimp(%epsilon[r](r)+%nu*%epsilon[%theta](r));

it gives me:

((c[1]*%nu+c[1])*r^2+c[2]*%nu+c[2])/r^2

enter image description here

Which is obviously wrong because the correct result can be calculated by:

fullratsimp((c[1]-c[2]/r^2)+%nu*(c[1]+c[2]/r^2));

enter image description here

I would appreciate if you could help me know what is the problem and how I can solve it.

Upvotes: 2

Views: 616

Answers (1)

Robert Dodier
Robert Dodier

Reputation: 17585

The problem is that foo[x1](y) := ... and foo[x2](y) := ... defines just one function foo, and the second definition clobbers the first one, so that only foo[x2](y) := ... is defined.

You can get the effect you want by creating lambda expressions (unnamed functions) and assigning them to subscripted variables.

(%i1) %epsilon[r](r):=c[1]-c[2]/r^2 $
(%i2) %epsilon[%theta](r):=c[1]+c[2]/r^2 $
(%i3) %epsilon[r];
                                  c
                                   2
(%o3)                 lambda([r], -- + c )
                                   2    1
                                  r
(%i4) %epsilon[%theta];
                                  c
                                   2
(%o4)                 lambda([r], -- + c )
                                   2    1
                                  r
(%i5) kill(%epsilon) $
(%i6) %epsilon[r] : lambda([r], c[1]-c[2]/r^2) $
(%i7) %epsilon[%theta] : lambda([r], c[1]+c[2]/r^2) $
(%i8) %epsilon[r];
                                       c
                                        2
(%o8)                 lambda([r], c  - --)
                                   1    2
                                       r
(%i9) %epsilon[%theta];
                                       c
                                        2
(%o9)                 lambda([r], c  + --)
                                   1    2
                                       r
(%i10) fullratsimp(%epsilon[r](r)+%nu*%epsilon[%theta](r));
                                2
                 (c  %nu + c ) r  + c  %nu - c
                   1        1        2        2
(%o10)           ------------------------------
                                2
                               r

Note that foo[x](y) := ... also creates lambda expressions, but you need to ensure your own definition here, not the definition which is created automatically by Maxima.

Upvotes: 2

Related Questions