> with(linalg):
Warning, the protected names norm and trace have been redefined and
unprotected

> Matrix_d:= matrix(1,3,[d[1],d[2],d[3]]);

                  Matrix_d := [d[1]    d[2]    d[3]]

> J:= multiply(transpose(Matrix_d),S*Matrix_d):
> K:= Int(evalm(J),x);

              / [        2                                ]
             |  [  S d[1]       d[1] S d[2]    d[1] S d[3]]
             |  [                                         ]
       K :=  |  [                       2                 ] dx
             |  [d[1] S d[2]      S d[2]       d[2] S d[3]]
             |  [                                         ]
             |  [                                      2  ]
            /   [d[1] S d[3]    d[2] S d[3]      S d[3]   ]

# Die quadratischen "shape functions" lauten:
> N[1]:=x-> 1-3*x+2*x^2;  N[2]:= x-> 4*x*(1-x);  N[3]:= x->x*(-1+2*x); 

                                               2
                     N[1] := x -> 1 - 3 x + 2 x


                       N[2] := x -> 4 x (1 - x)


                      N[3] := x -> x (-1 + 2 x)

# Die Summe der Produkte aus den "shape functions" mit den
# entsprechenden Knotenwerten ist:
> S:= x-> N[1]*y[1] + N[2]*y[2] + N[3]*y[3];

             S := x -> N[1] y[1] + N[2] y[2] + N[3] y[3]

# Unter Bercksichtigung der Randbedingugen y1 = y(0) = 1 und y3 =y(1) =
# 0 wird: 
> S := x-> 1-3*x+2*x^2 + 4*x*(1-x)*y[2];

                                    2
             S := x -> 1 - 3 x + 2 x  + 4 x (1 - x) y[2]

# Die erste Ableitung der "shape funktions"  fhrt auf die Gren
# d1,d2,d3 in obiger  Matrix:
> d[1] := x-> - 3 +4*x;         d[2] := x-> 4 -8*x;         d[3] := x->
> -1 +4*x;

                        d[1] := x -> -3 + 4 x


                         d[2] := x -> 4 - 8 x


                        d[3] := x -> -1 + 4 x

# Die "Steifigkeitsmatrix"  [K] ergibt sich zu:
> p := map(int,J(x),x = 0..1):   K:= (1/30)*evalm(30*p);

                [37 + 36 y[2]     -44 - 32 y[2]     7 - 4 y[2] ]
                [                                              ]
      K := 1/30 [-44 - 32 y[2]    48 + 64 y[2]     -4 - 32 y[2]]
                [                                              ]
                [ 7 - 4 y[2]      -4 - 32 y[2]     -3 + 36 y[2]]

> Inverse(K) := inverse(K);
Error, (in inverse) singular matrix

# Die "Steifigkeitsmatrix ist symmetrisch und singulr. Den "Lastvektor"
# {F} ermittelt man gem: 
> Matrix_N := matrix(1,3,[N[1],N[2],N[3]]):   F := -
> map(Int,Matrix_N,x=0..1); 

               [   1               1               1        ]
               [  /               /               /         ]
               [ |               |               |          ]
         F := -[ |   N[1] dx     |   N[2] dx     |   N[3] dx]
               [ |               |               |          ]
               [/               /               /           ]
               [  0               0               0         ]

> q := -map(int,Matrix_N(x),x=0..1):    F := (1/30)*evalm(30*q);

                     F := 1/30 [-5    -20    -5]

# Zur Bestimmung des Knotenwertes y2 erhlt man aus der 
# Matrizengeleichung drei algebraische Gleichungen: 
> eqn[1] := expand(37 + 36*y[2] - (32*y[2] + 44)*y[2]) = - 5;

                                               2
                eqn[1] := 37 - 8 y[2] - 32 y[2]  = -5

> eqn[2] := expand(-44 - 32*y[2] + (48+64*y[2])*y[2]) = - 20;

                                                2
               eqn[2] := -44 + 16 y[2] + 64 y[2]  = -20

> eqn[3] := expand(7 - 4*y[2] - (4+32*y[2])*y[2]) = - 5;

                                               2
                 eqn[3] := 7 - 8 y[2] - 32 y[2]  = -5

# Die Lsung dieser Gleichungen ergeben sich zu:
> L[1]:= evalf(solve(eqn[1]));

                  L[1] := -1.277443057, 1.027443057

> L[2]:= solve(eqn[2]);

                          L[2] := 1/2, -3/4

> L[3]:= solve(eqn[3]);

                          L[3] := -3/4, 1/2

# Von diesen Lsungen liegt nur der Wert y2 = 1/2 im betrachteten
# Bereich 0 < x < 1 und stimmt mit dem exakten Wert berein. Damit
# erhlt man die Nherung:
>  
> Y := N[1] + N[2]*y[2];

                        Y := N[1] + N[2] y[2]

> Y := expand(N[1](x) + N[2](x)/2);

                      Y := N[1](x) + 1/2 N[2](x)

# die mit der exakten Lsung bereinstimmt !
