An algebra problem by Rocco Dalto

Algebra Level pending

Let f : P 2 A 2 X 2 f: \mathbb P_{2} \rightarrow \mathbb A_{2 X 2} be linear transform defined by:

f ( p 1 + p 2 x + p 3 x 2 ) = p 1 p 2 + p 3 2 p 1 3 p 2 p 3 3 p 1 + p 2 2 p 3 4 p 1 + 2 p 2 + p 3 f(p1 + p2 * x + p3 * x^2) = \begin{vmatrix}{p_{1} - p_{2} + p_{3}} && {2 * p_{1} - 3 * p_{2} - p_{3}} \\ {3 * p_{1} + p_{2} - 2 * p_{3}} && {4 * p_{1} + 2 * p_{2} + p_{3}}\end{vmatrix}

Let A = { 1 + 2 x + 3 x 2 , 3 2 x + 4 x 2 , 5 + 4 x + 3 x 2 } A = \{ 1 + 2 * x + 3 * x^2, \: 3 - 2 * x + 4 * x^2, \: 5 + 4 * x + 3 * x^2\} be a basis for P 2 \mathbb P_{2} .

Let B = { 1 2 3 4 , 2 5 7 2 , 1 1 2 1 , 3 2 1 4 } B = \{ \begin{vmatrix}{1} && {2} \\ {3} && {4}\end{vmatrix}, \begin{vmatrix}{-2} && {5} \\ {7} && {2}\end{vmatrix}, \begin{vmatrix}{1} && {1} \\ {2} && {-1}\end{vmatrix}, \begin{vmatrix}{3} && {2} \\ {-1} && {4}\end{vmatrix} \} be a basis for A 2 X 2 \mathbb A_{2 X 2} .

If M = [ a i j ] 4 x 3 M = [a_{ij}]_{4 \: x \: 3} represents the linear transform above find S = i = 1 4 j = 1 3 a i j . \displaystyle S = \sum_{i = 1}^{4} \sum_{j = 1}^{3} a_{i j}.

Express the result to four decimal places.

If your interested you can write a program(in any language) for the General Case below and use it to find the above result.

For General Case:

Let f : P m 1 A n X n f: \mathbb P_{m - 1} \rightarrow \mathbb A_{n X n} be linear transform defined by:

f ( p 1 + p 2 x + p 3 x 2 + . . . + p m x m 1 ) = [ S p j ( p 1 , p 2 , . . . , p m ) ] n X n f(p_1 + p_2 * x + p_3 * x^2 + ... + p_m * x^{m - 1}) = [ S_{pj}(p_{1},p_{2},...,p_{m}) ]_{n X n} , where S p j ( p 1 , p 2 , . . . , p m ) = p = 1 n j = 1 n k = 1 m c j k p p k S_{pj}(p_{1},p_{2},...,p_{m}) = \sum_{p = 1}^{n} \sum_{j = 1}^{n} \sum_{k = 1}^{m} c_{jkp} * p_{k} .

Let W q = p 1 q + p 2 q x + . . . + p m q x m 1 P m 1 W_{q} =p_{1q} + p_{2q} * x + ... + p_{mq} * x^{m - 1} \in \mathbb P_{m - 1}

and A = { W q ( 1 < = q < = m ) } A = \{ W_{q} | (1 <= q <= m) \} be a basis for P m 1 \mathbb P_{m - 1} .

Let M q = [ a j k q ] n X n M_{q} = [a_{jkq}]_{n X n} and

B = { M q ( 1 < = q < = n 2 ) } B = \{ M_{q} | (1 <= q <= n^2) \} be a basis for A n X n \mathbb A_{n X n} .

Write a program in any language to find the matrix M = [ a i j ] n 2 x m M = [a_{ij}]_{n^2 \: x \: m} representation of the general linear transform above and the sum S = i = 1 n 2 j = 1 m a i j \displaystyle S = \sum_{i = 1}^{n^2} \sum_{j = 1}^{m} a_{i j} .

Make certain A A and B B are bases for P m 1 \mathbb P_{m - 1} and A n X n \mathbb A_{n X n} .

You can use the program written to find the matrix M = [ a i j ] 4 x 3 M = [a_{ij}]_{4 \: x \: 3} that represents the linear transform above and output S = i = 1 4 j = 1 3 a i j \displaystyle S = \sum_{i = 1}^{4} \sum_{j = 1}^{3} a_{i j} .

Let p = 1 2 x + x 2 p = 1 - 2 * x + x^2

To check the matrix M = [ a i j ] 4 x 3 M = [a_{ij}]_{4 \: x \: 3} found, first find [ f ( p ) ] B [f(p)]_B without using the matrix M = [ a i j ] 4 x 3 M = [a_{ij}]_{4 \: x \: 3} , then find [ f ( p ) ] B [f(p)]_B using the matrix M = [ a i j ] 4 x 3 M = [a_{ij}]_{4 \: x \: 3} .

Refer to previous problem. . .

I intentional used p 1 + p 2 x + p 3 x 2 + . . . + p m x m 1 p_1 + p_2 * x + p_3 * x^2 + ... + p_m * x^{m - 1} instead of the traditional p 0 + p 1 x + p 2 x 2 + . . . + p m x m p_{0} + p_{1} * x + p_{2} * x^2 + ... + p_{m} * x^m


The answer is 4.8765.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Rocco Dalto
Apr 21, 2017

After doing the problem I supply the program I wrote for the general case which generated the output for this specific problem.

Since f : P 2 A 2 X 2 f: \mathbb P_{2} \rightarrow \mathbb A_{2 X 2} is a linear transform, for each integer j ( 1 < = j < = 3 ) j \ni (1 <= j <= 3) f ( p 1 j + p 2 j x + p 3 j x 2 ) = α 1 j 1 2 3 4 + α 2 j 2 5 7 2 + α 3 j 1 1 2 1 + α 4 j 3 2 1 4 f(p_{1j} + p_{2j} * x + p_{3j} * x^2) = \alpha_{1j} * \begin{vmatrix}{1} && {2} \\ {3} && {4}\end{vmatrix} + \alpha_{2j} * \begin{vmatrix}{-2} && {5} \\ {7} && {2}\end{vmatrix} + \alpha_{3j} * \begin{vmatrix}{1} && {1} \\ {2} && {-1}\end{vmatrix} + \alpha_{4j} * \begin{vmatrix}{3} && {2} \\ {-1} && {4}\end{vmatrix} = [ 1 2 1 3 2 5 1 2 3 7 2 1 4 2 1 4 ] \begin{bmatrix}{1} && {-2} && {1} && {3} \\ {2} && {5} && {1} && {2} \\ {3} && {7} && {2} && {-1} \\ {4} && {2} && {-1} && {4}\end{bmatrix} * α 1 j α 2 j α 3 j α 4 j \begin{vmatrix}{\alpha{1j}} \\{\alpha{2j}} \\ {\alpha{3j}} \\ {\alpha{4j}}\end{vmatrix}

where,

f ( 1 + 2 x + 3 x 2 ) = 2 7 1 11 f(1 + 2 * x + 3 * x^2) = \begin{vmatrix}{2} && {-7} \\ {-1} && {11}\end{vmatrix}

f ( 3 2 x + 4 x 2 ) = 9 8 1 12 f(3 - 2 * x + 4 * x^2) = \begin{vmatrix}{9} && {8} \\ {-1} && {12}\end{vmatrix}

f ( 5 + 4 x + 3 x 2 ) = 4 5 13 31 f(5 + 4 * x + 3 * x^2) = \begin{vmatrix}{4} && {-5} \\ {13} && {31}\end{vmatrix}

Using the above we can set up the augmented matrix below to solve for the

three 4 X 4 systems of equations.

[ 1 2 1 3 2 9 4 2 5 1 2 7 8 5 3 7 2 1 1 1 13 4 2 1 4 11 12 31 ] \left[ \begin{array}{cccc|ccc} 1 & -2 & 1 & 3 & 2 & 9 & 4\\ 2 & 5 & 1 & 2 & -7 & 8 & -5\\ 3 & 7 & 2 & -1 & -1 & -1 & 13\\ 4 & 2 & -1 & 4 & 11 & 12 & 31\\ \ \end{array} \right]

2.0000 R O W 1 + R O W 2 -2.0000 * ROW_1 + ROW_2

3.0000 R O W 1 + R O W 3 -3.0000 * ROW_1 + ROW_3

4.0000 R O W 1 + R O W 4 -4.0000 * ROW_1 + ROW_4

[ 1.0000 2.0000 1.0000 3.0000 2.0000 9.0000 4.0000 0.0000 9.0000 1.0000 4.0000 11.0000 10.0000 13.0000 0.0000 13.0000 1.0000 10.0000 7.0000 28.0000 1.0000 0.0000 10.0000 5.0000 8.0000 3.0000 24.0000 15.0000 ] \left[ \begin{array}{cccc|ccc} 1.0000 & -2.0000 & 1.0000 & 3.0000 & 2.0000 & 9.0000 & 4.0000\\ 0.0000 & 9.0000 & -1.0000 & -4.0000 & -11.0000 & -10.0000 & -13.0000\\ 0.0000 & 13.0000 & -1.0000 & -10.0000 & -7.0000 & -28.0000 & 1.0000\\ 0.0000 & 10.0000 & -5.0000 & -8.0000 & 3.0000 & -24.0000 & 15.0000\\ \ \end{array} \right]

0.1111 R o w 2 0.1111 * Row2

[ 1.0000 2.0000 1.0000 3.0000 2.0000 9.0000 4.0000 0.0000 1.0000 0.1111 0.4444 1.2222 1.1111 1.4444 0.0000 13.0000 1.0000 10.0000 7.0000 28.0000 1.0000 0.0000 10.0000 5.0000 8.0000 3.0000 24.0000 15.0000 ] \left[ \begin{array}{cccc|ccc} 1.0000 & -2.0000 & 1.0000 & 3.0000 & 2.0000 & 9.0000 & 4.0000\\ 0.0000 & 1.0000 & -0.1111 & -0.4444 & -1.2222 & -1.1111 & -1.4444 \\ 0.0000 & 13.0000 & -1.0000 & -10.0000 & -7.0000 & -28.0000 & 1.0000\\ 0.0000 & 10.0000 & -5.0000 & -8.0000 & 3.0000 & -24.0000 & 15.0000\\ \ \end{array} \right]

2.0000 R O W 2 + R O W 1 2.0000 * ROW _2 + ROW_1

13.0000 R O W 2 + R O W 3 -13.0000 * ROW_2 + ROW_3

10.0000 R O W 2 + R O W 4 -10.0000 * ROW_ 2 + ROW_4

[ 1.0000 0.0000 0.7778 2.1111 0.4444 6.7778 1.1111 0.0000 1.0000 0.1111 0.4444 1.2222 1.1111 1.4444 0.0000 0.0000 0.4444 4.2222 8.8889 13.5556 19.7778 0.0000 0.0000 3.8889 3.5556 15.2222 12.8889 29.4444 ] \left[ \begin{array}{cccc|ccc} 1.0000 & 0.0000 & 0.7778 & 2.1111 & -0.4444 & 6.7778 & 1.1111 \\ 0.0000 & 1.0000 & -0.1111 & -0.4444 & -1.2222 & -1.1111 & -1.4444 \\ 0.0000 & 0.0000 & 0.4444 & -4.2222 & 8.8889 & -13.5556 & 19.7778 \\ 0.0000 & 0.0000 & -3.8889 & -3.5556 & 15.2222 & -12.8889 & 29.4444 \\ \ \end{array} \right]

2.2500 R o w 3 2.2500 * Row_3

[ 1.0000 0.0000 0.7778 2.1111 0.4444 6.7778 1.1111 0.0000 1.0000 0.1111 0.4444 1.2222 1.1111 1.4444 0.0000 0.0000 1.0000 9.5000 20.0000 30.5000 44.5000 0.0000 0.0000 3.8889 3.5556 15.2222 12.8889 29.4444 ] \left[ \begin{array}{cccc|ccc} 1.0000 & 0.0000 & 0.7778 & 2.1111 & -0.4444 & 6.7778 & 1.1111\\ 0.0000 & 1.0000 & -0.1111 & -0.4444 & -1.2222 & -1.1111 & -1.4444\\ 0.0000 & 0.0000 & 1.0000 & -9.5000 & 20.0000 & -30.5000 & 44.5000\\ 0.0000 & 0.0000 & -3.8889 & -3.5556 & 15.2222 & -12.8889 & 29.4444\\ \ \end{array} \right]

0.7778 R O W 3 + R O W 1 -0.7778 * ROW _3 + ROW_1

0.1111 R O W 3 + R O W 2 0.1111 * ROW_3 + ROW_2

3.8889 R O W 3 + R O W 4 3.8889 * ROW_3 + ROW_4

[ 1.0000 0.0000 0.0000 9.5000 16.0000 30.5000 33.5000 0.0000 1.0000 0.0000 1.5000 1.0000 4.5000 3.5000 0.0000 0.0000 1.0000 9.5000 20.0000 30.5000 44.5000 0.0000 0.0000 0.0000 40.5000 93.0000 131.5000 202.5000 ] \left[ \begin{array}{cccc|ccc} 1.0000 & 0.0000 & 0.0000 & 9.5000 & -16.0000 & 30.5000 & -33.5000\\ 0.0000 & 1.0000 & 0.0000 & -1.5000 & 1.0000 & -4.5000 & 3.5000\\ 0.0000 & 0.0000 & 1.0000 & -9.5000 & 20.0000 & -30.5000 & 44.5000\\ 0.0000 & 0.0000 & 0.0000 & -40.5000 & 93.0000 & -131.5000 & 202.5000\\ \ \end{array} \right]

0.0247 R o w 4 -0.0247 * Row_4

[ 1.0000 0.0000 0.0000 9.5000 16.0000 30.5000 33.5000 0.0000 1.0000 0.0000 1.5000 1.0000 4.5000 3.5000 0.0000 0.0000 1.0000 9.5000 20.0000 30.5000 44.5000 0.0000 0.0000 0.0000 1.0000 2.2963 3.2469 5.0000 ] \left[ \begin{array}{cccc|ccc} 1.0000 & 0.0000 & 0.0000 & 9.5000 & -16.0000 & 30.5000 & -33.5000 \\ 0.0000 & 1.0000 & 0.0000 & -1.5000 & 1.0000 & -4.5000 & 3.5000 \\ 0.0000 & 0.0000 & 1.0000 & -9.5000 & 20.0000 & -30.5000 & 44.5000 \\ 0.0000 & 0.0000 & 0.0000 & 1.0000 & -2.2963 & 3.2469 & -5.0000 \\ \ \end{array} \right]

9.5000 R O W 4 + R O W 1 -9.5000 * ROW_4 + ROW_1

1.5000 R O W 4 + R O W 2 1.5000 * ROW_4 + ROW_2

9.5000 R O W 4 + R O W 3 9.5000 * ROW_4 + ROW_3

[ 1.0000 0.0000 0.0000 0.0000 5.8148 0.3457 14.0000 0.0000 1.0000 0.0000 0.0000 2.4444 0.3704 4.0000 0.0000 0.0000 1.0000 0.0000 1.8148 0.3457 3.0000 0.0000 0.0000 0.0000 1.0000 2.2963 3.2469 5.0000 ] \left[ \begin{array}{cccc|ccc} 1.0000 & 0.0000 & 0.0000 & 0.0000 & 5.8148 & -0.3457 & 14.0000\\ 0.0000 & 1.0000 & 0.0000 & 0.0000 & -2.4444 & 0.3704 & -4.0000\\ 0.0000 & 0.0000 & 1.0000 & 0.0000 & -1.8148 & 0.3457 & -3.0000\\ 0.0000 & 0.0000 & 0.0000 & 1.0000 & -2.2963 & 3.2469 & -5.0000\\ \ \end{array} \right]

The desired matrix is:

M = [ 5.8148 0.3457 14.0000 2.4444 0.3704 4.0000 1.8148 0.3457 3.0000 2.2963 3.2469 5 ] M = \begin{bmatrix}{5.8148} && {-0.3457} && {14.0000} \\ {-2.4444} && {0.3704} && {-4.0000} \\ {-1.8148} && {0.3457} && {-3.0000} \\ {-2.2963} && {3.2469} && {-5}\end{bmatrix}

and i = 1 4 j = 1 3 a i j = 4.8765 \sum_{i = 1}^{4} \sum_{j = 1}^{3} a_{i j} = \boxed{4.8765} .

Check [ f ( p ) ] B : [f(p)]_{B}:

Without using matrix M : M:

Let p = 1 2 x + x 2 P 2 p = {1 - 2 * x + x^2} \in P_{2} \implies

f ( 1 2 x + x 2 ) = β 1 1 2 3 4 + β 2 2 5 7 2 + β 3 1 1 2 1 + β 4 3 2 1 4 f(1 -2 * x + x^2) = \beta_{1} * \begin{vmatrix}{1} && {2} \\ {3} && {4}\end{vmatrix} + \beta_{2} * \begin{vmatrix}{-2} && {5} \\ {7} && {2}\end{vmatrix} + \beta_{3} * \begin{vmatrix}{1} && {1} \\ {2} && {-1}\end{vmatrix} + \beta_{4} * \begin{vmatrix}{3} && {2} \\ {-1} && {4}\end{vmatrix} = [ 1 2 1 3 2 5 1 2 3 7 2 1 4 2 1 4 ] \begin{bmatrix}{1} && {-2} && {1} && {3} \\ {2} && {5} && {1} && {2} \\ {3} && {7} && {2} && {-1} \\ {4} && {2} && {-1} && {4}\end{bmatrix} * β 1 β 2 β 3 β 4 \begin{vmatrix}{\beta_{1}} \\{\beta_{2}} \\ {\beta{3}} \\ {\beta{4}}\end{vmatrix}

Using the above we can set up the augmented matrix:

[ 1.0000 2.0000 1.0000 3.0000 4.0000 2.0000 5.0000 1.0000 2.0000 7.0000 3.0000 7.0000 2.0000 1.0000 1.0000 4.0000 2.0000 1.0000 4.0000 1.0000 ] \left[ \begin{array}{cccc|c} 1.0000 & -2.0000 & 1.0000 & 3.0000 & 4.0000\\ 2.0000 & 5.0000 & 1.0000 & 2.0000 & 7.0000\\ 3.0000 & 7.0000 & 2.0000 & -1.0000 & -1.0000\\ 4.0000 & 2.0000 & -1.0000 & 4.0000 & 1.0000\\ \ \end{array} \right]

Using row operations on the above augmented matrix we obtain:

[ 1.0000 0.0000 0.0000 0.0000 2.9753 0.0000 1.0000 0.0000 0.0000 1.2593 0.0000 0.0000 1.0000 0.0000 0.9753 0.0000 0.0000 0.0000 1.0000 2.8395 ] \left[ \begin{array}{cccc|c} 1.0000 & 0.0000 & 0.0000 & 0.0000 & -2.9753\\ 0.0000 & 1.0000 & 0.0000 & 0.0000 & 1.2593\\ 0.0000 & 0.0000 & 1.0000 & 0.0000 & 0.9753\\ 0.0000 & 0.0000 & 0.0000 & 1.0000 & 2.8395\\ \ \end{array} \right]

\implies

[ f ( p ) ] B = ( 2.9753 1.2593 0.9753 2.8395 ) [f(p)]_{B} = \left( \begin{array}{ccccc} -2.9753\\ 1.2593\\ 0.9753\\ 2.8395\\ \end{array} \right)

Using matrix M M :

Using the set of basis vectors for A A and p p we set up the system:

[ 1.0000 3.0000 5.0000 1.0000 2.0000 2.0000 4.0000 2.0000 3.0000 4.0000 2.0000 1.0000 ] \left[ \begin{array}{ccc|c} 1.0000 & 3.0000 & 5.0000 & 1.0000 \\ 2.0000 & -2.0000 & 4.0000 & -2.0000 \\ 3.0000 & 4.0000 & 2.0000 & 1.0000 \\ \end{array} \right]

Solving the system we obtain:

[ p ] A = [ 0.3333 0.5455 0.0606 ] [p]_A = \left[ \begin{array}{ccccc} -0.3333 \\ 0.5455\\ -0.0606\\ \end{array} \right]

\implies

[ f ( p ) ] B = M [ p ] A = [ 5.8148 0.3457 14.0000 2.4444 0.3704 4.0000 1.8148 0.3457 3.0000 2.2963 3.2469 5 ] [ 0.3333 0.5455 0.0606 ] = ( 2.9753 1.2593 0.9753 2.8395 ) [f(p)]_B = M * [p]_A = \begin{bmatrix}{5.8148} && {-0.3457} && {14.0000} \\ {-2.4444} && {0.3704} && {-4.0000} \\ {-1.8148} && {0.3457} && {-3.0000} \\ {-2.2963} && {3.2469} && {-5}\end{bmatrix} * \left[ \begin{array}{ccc} -0.3333 \\ 0.5455 \\ -0.0606\\ \end{array} \right] = \left( \begin{array}{ccccc} -2.9753\\ 1.2593\\ 0.9753\\ 2.8395\\ \end{array} \right)

I wrote the program in Free Pascal.

program matrixrepresentaionoflineartransform_2;

{$R-}

{restricted to f:Rm --> Anxn}

uses crt;

                                {self contained for brillant}

const maxnum = 100;

type Tmatrix = array[1 .. maxnum,1 .. maxnum,1 .. maxnum] of real;

  matrix = array[1 .. maxnum,1 .. maxnum] of real;

var coeff:Tmatrix;

a,b,c,d,sol,prod,e:matrix;


n,m,l,p,v:integer;

mywork2:text;

deta,detb,product:real;

f:matrix;{for me only-check}

function intpower(base,exponent:integer):longint;

var product,k:longint;

begin{intpower}

product:= 1;

 for k:= 1 to exponent do

      product:= product * base;


 INTpower:= product;

end;{intpower}

procedure Getsize;

begin

writeln('Enter m for each basis vectors in Rm');

readln(m);

m:= m + 1;

writeln('Enter n for each n x n matrix');

readln(n);

end;

procedure getcoefficients;

var j,k,p:integer;

begin

for p:= 1 to n do

begin

for j:= 1 to n do

begin

write('Enter coefficients of row',p,' column', j,' :');

for k:= 1 to m do

begin

read(coeff[j,k,p]);

end;

end;

end;

{test}

{for p:= 1 to n do

begin

for j:= 1 to n do

begin

for k:= 1 to m do

begin

write(coeff[j,k,p]:0:4,' ');

end;

write;

end;

writeln;

end; }

end;

procedure Getmatrices;

var j,k,q,p:integer;

c:matrix;

sum:real;

myfile:text;

s:Tmatrix;

begin

assign(myfile,'holdmatrix2.txt');

rewrite(myfile);

writeln('To Enter ', m, ' basis vectors for P',m - 1,': ');

for q:= 1 to m do

begin

write('Enter coefficients of polynomial ', q, ' : ');

for q:= 1 to m do

begin

write('Enter elements of polynomial ', q, ' : ');

for k:= 1 to m do

begin

read(b[k,q]);

end;

end;

{test}

{for q:= 1 to m do

begin

for k:= 1 to m do

begin

write(b[k,q]:0:4,' ');

end;

writeln;

end; }

{To set up coefficients of system}

for j:= 1 to intpower(n,2) do

begin

writeln('Enter Matrix',j,' on one line:');

for k:= 1 to intpower(n,2) do

begin

read(c[k,j]);

end;

end;

for j:= 1 to intpower(n,2) do

begin

for k:= 1 to intpower(n,2) do

begin

a[j,k]:= c[j,k];

end;

end;

{test}

{for j:= 1 to intpower(n,2) do

begin

for k:= 1 to intpower(n,2) do

begin

write(a[j,k]:0:4,' ');

end;

writeln;

end; }

{For f(X) - test o.k.}

{for q:= 1 to m do

begin

for p:= 1 to n do

begin

for j:= 1 to n do

begin

sum:= 0;

for k:= 1 to m do

begin

sum:= sum + coeff[j,k,p] * b[k,q];

end;

s[p,j,q]:= sum;

end;

end;

end; }

{for q:= 1 to m do

begin

for p:= 1 to n do

begin

for j:= 1 to n do

begin

write(s[p,j,q]:0:4,' ');

end;

writeln;

end;

writeln;

writeln;

end; }

for q:= 1 to m do

begin

for p:= 1 to n do

begin

for j:= 1 to n do

begin

sum:= 0;

for k:= 1 to m do

begin

sum:= sum + coeff[j,k,p] * b[k,q];

end;

write(myfile,sum,' ');

end;

end;

end;

reset(myfile);

for j:= 1 to m do

begin

for k:= 1 to intpower(n,2) do

begin

read(myfile,a[k,intpower(n,2) + j]);

end;

end;

{writeln;

writeln(' Solve the',intpower(n,2),' X ',intpower(n,2),' system using the augmented matrix below:');

writeln;

for j:= 1 to intpower(n,2) do

begin

for k:= 1 to intpower(n,2) + m do

begin

write(a[j,k]:0:4,' ');

end;

writeln;

end; }

close(myfile);

for j:= 1 to intpower(n,2) do

begin

for k:= 1 to intpower(n,2) + m do

begin

write(mywork2,a[j,k]:0:4,' ');

end;

writeln(mywork2);

end;

end;

{Now to solve - easy N^2 X N^2 system of equations}

{Put determinant here later to check bases}

procedure hold(var c:matrix; e:matrix; m:integer);

var k,j:integer;

begin

for k:= 1 to m do

begin

for j:= 1 to m do

begin

c[k,j]:= e[k,j];

end;

end;

end;

{Determinants-To check Basis}

procedure switch2(var c:matrix; l,p,n:integer);

var q:integer;

z:real;

begin{switch}

for q:= 1 to n do

begin{m}

   z:= c[l,q];

   c[l,q]:= c[p,q];

   c[p,q]:= z;

end;{m}

end;{switch}

procedure safeguard2(var c:matrix; l:integer; var p:integer; n:integer; var v:integer; var product:real);

var q:integer;

begin{safeguard}

v:=0;

if (c[l,l] = 0) then

begin{then}

v:= 1;

q:= l;

while ((q + 1) <= n) and (v = 1) do

begin{loop}

if c[q + 1,l] <> 0 then

begin{then}

        p:= q + 1;

        switch2(c,l,p,n);

        v:= 0;

        PRODUCT:= -1 * PRODUCT;

end;{then}

q:= q + 1;

end;{loop}

end;{then}

end;{safeguard}

procedure operation11(var a:matrix; l,n:integer; var product:real);

var k,q:integer;

x:real;

s:matrix;

begin{operation11}

for q:= 1 to n do

begin{q}

s[l,q]:= a[l,q]/a[l,l];

end;{q}

PRODUCT:= PRODUCT * (1/A[L,L]);

for q:= 1 to n do

begin{q}

a[l,q]:= s[l,q];

end;{q}

    end;{operation11}

procedure operation21(var a:matrix; l,n:integer);

var k,r,q:integer;

x:real;

s:matrix;

begin{op2}

for q:= 1 to n do

begin{q}

if q <> l then

begin{then}

x:= -1 * a[q,l];

for r:= 1 to n do

begin{r}

s[q,r]:= x * a[l,r] + a[q,r];

end;{r}

for r:= 1 to n do

begin{r}

a[q,r]:= s[q,r];

end;{r}

end;{then}

end;{q}

end;{op2}

FUNCTION DETERMINANT(a:matrix; n:integer; PRODUCT:real):real;

var j:integer;

DET,DIAGONAL:real;

begin{DETERMINANT}

DIAGONAL:= 1;

FOR j:= 1 TO N DO

BEGIN{LOOP}

DIAGONAL:= DIAGONAL * (a[j,j]);

END;{LOOP}

IF DIAGONAL = 1 THEN

DET:= 1/PRODUCT

ELSE

DET:= 0;

DETERMINANT:= DET;

END;{DETERMINANT}

procedure switch(var c:matrix; l,p:integer);

var q:integer;

z:real;

begin{switch}

for q:= 1 to intpower(n,2) + m do

begin{m}

   z:= c[l,q];

   c[l,q]:= c[p,q];

   c[p,q]:= z;

end;{m}

end;{switch}

procedure safeguard(var c:matrix; l:integer; var p:integer; var v:integer);

var q:integer;

begin{safeguard}

v:=0;

if (c[l,l] = 0) then

begin{then}

v:= 1;

q:= l;

while ((q + 1) <= intpower(n,2) + m) and (v = 1) do

begin{loop}

if c[q + 1,l] <> 0 then

begin{then}

        p:= q + 1;

        switch(c,l,p);

        v:= 0;

end;{then}

q:= q + 1;

end;{loop}

end;{then}

end;{safeguard}

procedure operation1(var a:matrix; l:integer);

var q,k:integer;

s:matrix;

x:real;

                   {s is each transformed matrix}

begin{op1}

for q:= 1 to intpower(n,2) + m do

begin{m}

s[l,q]:= a[l,q]/a[l,l];

end;{m}

x:= 1/(a[l,l]);

for q:= 1 to intpower(n,2) + m do

begin{m}

a[l,q]:= s[l,q];

end;{m}

writeln(mywork2, x:0:4,' * Row',l);

writeln(mywork2);

for q:= 1 to intpower(n,2) do

begin

for k:= 1 to intpower(n,2) + m do

begin

write(mywork2, a[q,k]:0:4,' ');

end;

writeln(mywork2);

end;

writeln(mywork2);

end;{op1}

procedure operation2(var a:matrix; l:integer);

var q,r,k:integer;

x:real;

s:matrix;

begin{op2}

for q:= 1 to intpower(n,2) do

begin{q}

if q <> l then

begin{then}

x:= a[q,l];

for r:= 1 to intpower(n,2) + m do

begin{m}

s[q,r]:= -1 * x * a[l,r] + a[q,r];

end;{m}

for r:= 1 to intpower(n,2) + m do

begin{m}

a[q,r]:= s[q,r];

end;{m}

writeln(mywork2, -1 * x:0:4,' * ROW ', l,' + ROW',q);

end;{then}

end;{q}

writeln(mywork2);

for q:= 1 to intpower(n,2) do

begin

for k:= 1 to intpower(n,2) + m do

begin

write(mywork2, a[q,k]:0:4,' ');

end;

writeln(mywork2);

end;

writeln(mywork2);

end;{op2}

PROCEDURE SHOWDATA;

VAR J,k:INTEGER;

sum:extended;

myfile2:text;

BEGIN

assign(myfile2,'holdsolution2.txt');

rewrite(myfile2);

writeln;

writeln('Matrix Representation of linear transformation f: Rn ---> Rm:');

writeln('-------------------------------------------------------------');

writeln;

for j:= 1 to intpower(n,2) do

begin

for k:= intpower(n,2) + 1 to intpower(n,2) + m do

begin

write(myfile2,a[j,k],' ');

end;

writeln(myfile2);

end;

reset(myfile2);

for j:= 1 to intpower(n,2) do

begin

for k:= 1 to m do

begin

read(myfile2,sol[j,k]);

end;

end;

close(myfile2);

for j:= 1 to intpower(n,2) do

begin

for k:= 1 to m do

begin

write(sol[j,k]:0:4,' ');

end;

writeln;

end;

{For brillant only}

sum:= 0;

for j:= 1 to intpower(n,2) do

begin

for k:= 1 to m do

begin

sum:= sum + sol[j,k];

end;

end;

writeln;

writeln('Sum of elements of matrix = ',sum:0:4);

END;

{for me only}

                                        {just for me-begin}

procedure switch3(var c:matrix; l,p,n:integer);

var r:integer;

z:real;

begin{switch3}

for r:= 1 to n + 1 do

begin{m}

   z:= c[l,r];

   c[l,r]:= c[p,r];

   c[p,r]:= z;

end;{m}

end;{switch3}

procedure safeguard3(var c:matrix; l:integer; var p:integer; n:integer; var v:integer);

var r:integer;

begin{safeguard3}

v:=0;

if (c[l,l] = 0) then

begin{then}

v:= 1;

r:= l;

while ((r + 1) <= n) and (v = 1) do

begin{loop}

if c[r + 1,l] <> 0 then

begin{then}

        p:= r + 1;

        switch3(c,l,p,n);

        v:= 0;

end;{then}

r:= r + 1;

end;{loop}

end;{then}

end;{safeguard3}

procedure operation13(var a:matrix; l,n:integer);

var r,k:integer;

s:matrix;

x:real;

                  {s is each transformed matrix}

begin{op13}

for r:= 1 to n + 1 do

begin{r}

s[l,r]:= a[l,r]/a[l,l];

end;{r}

x:= 1/(a[l,l]);

for r:= 1 to n + 1 do

begin{m}

a[l,r]:= s[l,r];

end;{r}

end;{op13}

procedure operation23(var a:matrix; l,n:integer);

var q,r:integer;

x:real;

s:matrix;

begin{op23}

for q:= 1 to n do

begin{q}

if q <> l then

begin{then}

x:= a[q,l];

for r:= 1 to n + 1 do

begin{r}

s[q,r]:= -1 * x * a[l,r] + a[q,r];

end;{r}

for r:= 1 to n + 1 do

begin{r}

a[q,r]:= s[q,r];

end;{r}

end;{then} end;{q}

end;{op23}

procedure solution(y:matrix; n:integer);

var q:integer;

begin{solution}

for q:= 1 to n do

begin{q}

writeln(mywork2,y[q,n + 1]:0:4,'   ');

end;{q}

writeln(mywork2);

end;{solution}

procedure matrixmult(a,b:matrix; var summat:matrix);

var j,k,s:integer;

   sum:real;

begin{matrixmult}

for j:= 1 to intpower(n,2) do

begin{j}

for k:= 1 to 1 do

begin{k}

     sum:= 0;

for s:= 1 to m do

begin{s}

     sum:= sum + a[j,s] * b[s,k];

end;{s}

      summat[j,k]:= sum;

              end;{k}

writeln(mywork2,sum:0:4);

end;{j}

writeln(mywork2);

end;{matrixmult}

procedure check;

type arraytype = array[1 .. maxnum] of real;

var x:arraytype;

p,j,k:integer;

sum:real;

u:matrix;

myfile:text;

begin

assign(myfile,'holdmatrix3.txt');

rewrite(myfile);

{without using matrix}

writeln('Enter a basis vector for P',m - 1);

for j:= 1 to m do

begin

read(x[j]);

end;

for p:= 1 to n do

begin

for j:= 1 to n do

begin

sum:= 0;

for k:= 1 to m do

begin

sum:= sum + coeff[j,k,p] * x[k];

end; write(myfile,sum,' ');

end;

end;

reset(myfile);

for k:= 1 to intpower(n,2) do

begin

read(myfile,f[k,intpower(n,2) + 1]);

end;

close(myfile);

for j:= 1 to intpower(n,2) do

begin

for k:= 1 to intpower(n,2) + 1 do

begin

write(mywork2,f[j,k]:0:4,' ');

end;

writeln(mywork2);

end;

{Next Use operations on matrix f}

writeln(mywork2);

writeln(mywork2, 'Check [f(p)]B');

writeln(mywork2);

for l:= 1 to intpower(n,2) do

begin{l}

safeguard3(f,l,p,intpower(n,2),v);

if v = 0 then

begin{then}

operation13(f,l,intpower(n,2));

operation23(f,l,intpower(n,2));

end;{then}

end;{l}

writeln(mywork2);

solution(f,intpower(n,2));

{Now do using matrix M}

writeln(mywork2);

writeln(mywork2);

{To do}

for j:= 1 to m do

begin

e[j,m + 1]:= x[j];

end;

for j:= 1 to m do

begin

for k:= 1 to m + 1 do

begin

write(mywork2,e[j,k]:0:4,' ');

end;

writeln(mywork2);

end;

for l:= 1 to m do

begin{l}

safeguard3(e,l,p,m,v);

if v = 0 then

begin{then}

operation13(e,l,m);

operation23(e,l,m);

end;{then}

end;{l}

solution(e,m);

writeln(mywork2);

writeln(mywork2);

for j:= 1 to m do

begin

u[j,1]:= e[j,m + 1];

end;

writeln(mywork2);

writeln(mywork2);

matrixmult(sol,u,prod);

end;

begin

assign(mywork2,'mywork2.txt');

rewrite(mywork2);

getsize;

getcoefficients;

getmatrices;

hold(f,a,intpower(n,2)); {for me only-check}

hold(e,b,m);

{To do determinants to check bases here, then done.}

{checking basis for P(m - 1)}

PRODUCT:= 1;

for l:= 1 to m do

begin{l}

safeguard2(b,l,p,m,v,PRODUCT);

if v = 0 then

begin{then}

operation11(b,l,m,PRODUCT);

operation21(b,l,m);

end;{then}

end;{l}

DETB:= DETERMINANT(b,m,PRODUCT);

writeln;

while detb = 0 do

begin

writeln('Set of vectors is not a basis for P',m - 1);

writeln;

getmatrices;

PRODUCT:= 1;

for l:= 1 to m do

begin{l}

safeguard2(b,l,p,m,v,PRODUCT);

if v = 0 then

begin{then}

operation11(b,l,m,PRODUCT);

operation21(b,l,m); end;{then}

end;{l}

DETB:= DETERMINANT(b,m,PRODUCT);

end;

{checking basis for Anxn}

hold(c,a,intpower(n,2));

PRODUCT:= 1;

for l:= 1 to intpower(n,2) do

begin{l}

safeguard2(c,l,p,intpower(n,2),v,PRODUCT);

if v = 0 then

begin{then}

operation11(c,l,intpower(n,2),PRODUCT);

operation21(c,l,intpower(n,2));

end;{then}

end;{l}

DETA:= DETERMINANT(c,intpower(n,2),PRODUCT);

writeln;

while deta = 0 do

begin

writeln('Set of vectors is not a basis for A(',n,'X',n,')');

writeln;

getmatrices;

hold(c,a,intpower(n,2));

PRODUCT:= 1;

for l:= 1 to intpower(n,2) do

begin{l}

safeguard2(c,l,p,intpower(n,2),v,PRODUCT);

if v = 0 then

begin{then}

operation11(c,l,intpower(n,2),PRODUCT);

operation21(c,l,intpower(n,2));

end;{then}

end;{l}

DETA:= DETERMINANT(c,intpower(n,2),PRODUCT);

end;

{Only getting through if deta <> 0 and detb <> 0}

for l:= 1 to intpower(n,2) do

begin{l}

safeguard(a,l,p,v);

if v = 0 then

begin{then}

operation1(a,l);

operation2(a,l);

end;{then}

end;{l}

showdata;

check;

readln;

readln;

close(mywork2);

end.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...