3

I would like to ask:

  1. how I can add expressions in Maxima? i.e. I have:

    A = x + y;
    B = 2*x + 2*y;
    

    How to get Maxima to give me (A + B)?

  2. how I can do numerical calculation in Maxima? I want to assign

    x = 1;
    b = 2;
    

    How to get the numerical value of (A + B)?

ThisaruG
  • 3,222
  • 7
  • 38
  • 60
CaTx
  • 1,421
  • 4
  • 21
  • 42

2 Answers2

3

(1) assignment in Maxima uses the colon symbol (i.e., ":") not the equal sign ("=").

(2) there are a couple of ways to evaluate with specific values.

(2a) subst([x = ..., y = ...], foo) where foo is some expression such as foo : A + B.

(2b) ev(foo, x = ..., y = ...)

So:

 (%i1) A : x + y;
 (%o1)                                y + x
 (%i2) B : 2*x + 2*y;
 (%o2)                              2 y + 2 x
 (%i3) foo : A + B;
 (%o3)                              3 y + 3 x
 (%i4) subst ([x = 1, y = 2], foo);
 (%o4)                                  9
 (%i5) ev (foo, x = 1, y = 2);
 (%o5)                                  9
Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
0

Yet another way to substitute values into a formula is with the '' operator as follows:

(%i57) A : 2*a+b ; B : a-b;
(%o57)                              b + 2 a
(%o58)                               a - b
(%i59) a : 4; b : 10;
(%o59)                                 4
(%o60)                                10
(%i61) A;
(%o61)                              b + 2 a
(%i62) ''A;
(%o62)                                18
(%i63) ''B;
(%o64)                                - 6
(%i65) ''A + ''B;
(%o65)                                12
(%i66) ''(A+B);
(%o66)                                12
Persilja
  • 21
  • 4