How to ... in MuPAD ?

Also refer to Problems with ... in MuPAD ? which offers hints and work arounds for well known problems.

  1. ... insert comments ?
  2. ... read-in a file of commands ?
  3. ... unassign a variable ?
  4. ... define a matrix ?
  5. ... invert a matrix ?

  1. ... insert comments ?
    In MuPAD programs comments are enclosed between two hash symbols # and #.
    >> pi:= float(PI);  # it's a comment #  e:=float(E); 

  2. ... read-in a file of commands ?
    During a MuPAD session the function read can be used to read command files.
    >> read( "file" ); 
    On UNIX systems also the pipe mechanism of the shell can be used to start MuPAD with a special command file. This is often used for batch processing and also for demos.
    # cat in.mu
    fact(20); # this is factorial of 20 #
    quit;
    
    # mupad < in.mu
    >> fact(20); # this is factorial of 20 #
    2432902008176640000
    
    &> quit;
    #   

  3. ... unassign a variable ?
    Variables can be unassigned (returned it to its symbolic status) by assigning the value NIL.
    >> x:=42; x:= NIL: x;
    42
    x   

  4. ... define a matrix ?
    First load the linalg package, then define a matrix constructor with Matrix(D) or SquareMatrix(n,D) where D is a domain (the default is ExpressionField()) and n is an integer.
    >> loadlib("linalg"):
    >> M := Matrix(Rational):
    >> A := M([[1/2,1/3,3/5],[5/7,3,9/2]]);
    
                                +-               -+
                                | 1/2 , 1/3 , 3/5 |
                                |                 |
                                | 5/7 ,  3  , 9/2 |
                                +-               -+
    
    >> N := SquareMatrix(2):
    >> B := N([[cos(x),sin(x)],[exp(x),ln(x)]]);
    
                                +-               -+
                                | cos(x) , sin(x) |
                                |                 |
                                | exp(x) , ln(x)  |
                                +-               -+
    

  5. ... invert a matrix ?
    If A is a matrix then simply type 1/A. If the A cannot be inverted, the result is FAIL.


Author: MuPAD-webmaster
Last updated: 11. Oct. 1995