CS 723/823

Use of MAPLE for Solving Linear Equations

Suppose we want to solve the system of equations given below. The 6 global balance equations for states P00, P10, P20, P01, P11, and P02, respectively, are:

     8P10 + 4P01        = 2P00 + 2P00
     2P00 + 8P20 + 2P11 = 8P10 + 2P10 + 2P10 
     2P10               = 8P20
     2P00 + 4P11 + 4P02 = 4P01 + 2P01 +2P01
     2P10 + 2P01        = 2P11 + 4P11
     2P01               = 4P02

As noted, one of the equations is redundant, so we can (arbitrarily) replace one of the above equations, say, the last equation, with:

     P00 + P10 + P20 + P01 + P11 + P02 = 1

By rewriting, the resulting equations are:

     - 4P00 + 8P10 + 0P20 + 4P01 + 0P11 + 0P02 = 0
     + 2P00 -12P10 + 8P20 + 0P01 + 2P11 + 0P02 = 0
     + 0P00 + 2P10 - 8P20 + 0P01 + 0P11 + 0P02 = 0
     + 2P00 + 0P10 + 0P20 - 8P01 + 4P11 + 4P02 = 0
     + 0P00 + 2P10 + 0P20 + 2P01 - 6P11 + 0P02 = 0
     + 1P00 + 1P10 + 1P20 + 1P01 + 1P11 + 1P02 = 1

Instead of typing these equations directly in maple, you can redirect the input to the maple command, i.e., you can create a file of the commands you wish to execute and avoid retyping the global equations every time. Thus,

...create your input file, say input

indus{varki}50>>> cat input
# Comment Line
# Write down the Equations
E1 := - 4*P00 + 8*P10 + 0*P20 + 4*P01 + 0*P11 + 0*P02 = 0;
E2 := + 2*P00 -12*P10 + 8*P20 + 0*P01 + 2*P11 + 0*P02 = 0;
E3 := + 0*P00 + 2*P10 - 8*P20 + 0*P01 + 0*P11 + 0*P02 = 0;
E4 := + 2*P00 + 0*P10 + 0*P20 - 8*P01 + 4*P11 + 4*P02 = 0;
E5 := + 0*P00 + 2*P10 + 0*P20 + 2*P01 - 6*P11 + 0*P02 = 0;
E6 := + P00 + P10 + P20 + P01 + P11 + P02 = 1;

# Commands to solve the above set of equations.
EqArray := {E1, E2, E3, E4, E5, E6};
VarSet := {P00, P10, P20, P01, P11, P02};
assign(solve(EqArray, VarSet));

# Print the Probabilites
P00 := P00;
P10 := P10;
P20 := P20;
P01 := P01;
P11 := P11;
P02 := P02;

# Quit Maple
quit;
indus{varki}50>>> maple < input
    |\^/|     Maple V Release 4 (University of New Hampshire)
._|\|   |/|_. Copyright (c) 1981-1996 by Waterloo Maple Inc. All rights
 \  MAPLE  /  reserved. Maple and Maple V are registered trademarks of
 <____ ____>  Waterloo Maple Inc.
      |       Type ? for help.
# Comment Line
# Write down the Equations
> E1 := - 4.0*P00 + 8*P10 + 0*P20 + 4*P01 + 0*P11 + 0*P02 = 0;
                       E1 := -4.0 P00 + 8 P10 + 4 P01 = 0

> E2 := + 2*P00 -12*P10 + 8*P20 + 0*P01 + 2*P11 + 0*P02 = 0;
                    E2 := 2 P00 - 12 P10 + 8 P20 + 2 P11 = 0

> E3 := + 0*P00 + 2*P10 - 8*P20 + 0*P01 + 0*P11 + 0*P02 = 0;
                            E3 := 2 P10 - 8 P20 = 0

> E4 := + 2*P00 + 0*P10 + 0*P20 - 8*P01 + 4*P11 + 4*P02 = 0;
                    E4 := 2 P00 - 8 P01 + 4 P11 + 4 P02 = 0

> E5 := + 0*P00 + 2*P10 + 0*P20 + 2*P01 - 6*P11 + 0*P02 = 0;
                        E5 := 2 P10 + 2 P01 - 6 P11 = 0

> E6 := + P00 + P10 + P20 + P01 + P11 + P02 = 1;
                  E6 := P00 + P10 + P20 + P01 + P11 + P02 = 1

>
# Commands to solve the above set of equations.
> EqArray := {E1, E2, E3, E4, E5, E6};
EqArray := {-4.0 P00 + 8 P10 + 4 P01 = 0, 2 P00 - 12 P10 + 8 P20 + 2 P11 = 0,

    2 P10 - 8 P20 = 0, 2 P00 - 8 P01 + 4 P11 + 4 P02 = 0,

    2 P10 + 2 P01 - 6 P11 = 0, P00 + P10 + P20 + P01 + P11 + P02 = 1}

> VarSet := {P00, P10, P20, P01, P11, P02};
                    VarSet := {P00, P10, P20, P01, P11, P02}

> assign(solve(EqArray, VarSet));
>
# Print the Probabilites
> P00 := P00;
                               P00 := .4324324324

> P10 := P10;
                               P10 := .1081081081

> P20 := P20;
                              P20 := .02702702703

> P01 := P01;
                               P01 := .2162162162

> P11 := P11;
                               P11 := .1081081081

> P02 := P02;
                               P02 := .1081081081

>
# Quit Maple
> quit;
bytes used=1683584, alloc=1179432, time=0.45

Return to the CS 823 Home Page