An algebra problem by Rocco Dalto

Algebra Level pending

Let f : R 4 P 3 f: \mathbb R^4 \rightarrow \mathbb P_{3} be linear transform defined by:

f ( p 1 p 2 p 3 p 4 ) = p 1 + p 2 x + p 3 x 2 + p 4 x 3 f \left( \begin{array}{cccc} p_{1} \\ p_{2} \\ p_{3} \\ p_{4} \\ \end{array} \right) = p1 + p2 * x + p3 * x^2 + p4 * x^3

Let A = { ( 1 2 3 4 ) , ( 1 1 2 4 ) , ( 1 1 1 2 ) , ( 1 4 2 3 ) } A = \{ \left( \begin{array}{cccc} 1 \\ 2 \\ 3 \\ 4 \\ \end{array} \right), \left( \begin{array}{cccc} 1 \\ -1 \\ 2 \\ 4 \\ \end{array} \right), \left( \begin{array}{cccc} 1 \\ 1 \\ -1 \\ 2 \\ \end{array} \right), \left( \begin{array}{cccc} 1 \\ 4 \\ 2 \\ 3 \\ \end{array} \right) \} be a basis for R 4 \mathbb R^4 .

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

If M = [ a i j ] 4 x 4 M = [a_{ij}]_{4 \: x \: 4} represents the linear transform above find S = i = 1 4 j = 1 4 a i j . \displaystyle S = \sum_{i = 1}^{4} \sum_{j = 1}^{4} 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.

General Case(for program)

Let f : R n P n 1 f: \mathbb R^n \rightarrow \mathbb P_{n - 1} be linear transform defined by:

f ( p 1 p 2 . . . p j . . . p n ) = j = 1 n p j x j 1 f \left( \begin{array}{cccccccccc} p_{1} \\ p_{2} \\ . \\ . \\ . \\ p_{j} \\ . \\ . \\ . \\ p_{n} \\ \end{array} \right) = \sum_{j = 1}^{n} p_{j} * x^{j - 1}

Let V q = ( p 1 q p 2 q . . . p j q . . . p n q ) V_{q} = \left( \begin{array}{cccccccccc} p_{1q} \\ p_{2q} \\ . \\ . \\ . \\ p_{jq} \\ . \\ . \\ . \\ p_{nq} \\ \end{array} \right)

and A = { V q ( 1 < = q < = n ) } A = \{V_{q}| (1 <= q <= n) \} be a basis for R n \mathbb R^n

Let W q = j = 1 n p j q x j 1 W_{q} = \sum_{j = 1}^{n} p_{jq} * x^{j - 1}

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

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

Make certain A A and B B are bases for R n \mathbb R^{n} and P n 1 \mathbb P_{n - 1} .

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

Let X = ( 1 3 7 5 ) X = \left( \begin{array}{cccc} 1 \\ 3\\ 7 \\ -5 \\ \end{array} \right)

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


The answer is 0.7143.

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 27, 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 : R 4 P 3 f: \mathbb R^4 \rightarrow \mathbb P_{3} is a linear transform, for each integer j ( 1 < = j < = 4 ) j \ni (1 <= j <= 4)

f ( p 1 j p 2 j p 3 j p 4 j ) = k = 1 4 p k j x k 1 = α 1 j ( 1 + x x 2 + x 3 ) + α 2 j ( 1 x 2 ) + α 3 j ( x 3 x 2 x 3 ) + α 4 j ( 1 + 2 x 3 x 2 4 x 3 ) f \left( \begin{array}{cccc} p_{1j} \\ p_{2j} \\ p_{3j} \\ p_{4j} \\ \end{array} \right) = \sum_{k = 1}^{4} p_{kj} * x^{k - 1} = \alpha_{1j} * (1 + x - x^2 + x^3) + \alpha_{2j} * (1 - x^2) + \alpha_{3j} * (x - 3 * x^2 - x^3) + \alpha_{4j} * (1 + 2 * x - 3 * x^2 - 4 * x^3)

= [ 1 1 0 1 1 0 1 2 1 1 3 3 1 0 1 4 ] α 1 j α 2 j α 3 j α 4 j = \begin{bmatrix}{1} && {1} && {0} && {1} \\ {1} && {0} && {1} && {2} \\ {-1} && {-1} && {-3} && {-3} \\ {1} && {0} && {-1} && {-4}\end{bmatrix} * \begin{vmatrix}{\alpha_{1j}} \\{\alpha_{2j}} \\ {\alpha_{3j}} \\ {\alpha_{4j}}\end{vmatrix}

where,

f ( 1 2 3 4 ) = 1 + 2 x + 3 x 2 + 4 x 3 f \left( \begin{array}{cccc} 1 \\ 2 \\ 3 \\ 4 \\ \end{array} \right) = 1 + 2* x + 3 * x^2 + 4 * x^3

f ( 1 1 2 4 ) = 1 x + 2 x 2 + 4 x 3 f \left( \begin{array}{cccc} 1 \\ -1 \\ 2 \\ 4 \\ \end{array} \right) = 1 - x + 2 * x^2 + 4 * x^3

f ( 1 1 1 2 ) = 1 + x x 2 + 2 x 3 f \left( \begin{array}{cccc} 1 \\ 1 \\ -1 \\ 2 \\ \end{array} \right) = 1 + x - x^2 + 2 * x^3

f ( 1 4 2 3 ) = 1 + 4 x + 2 x 2 + 3 x 3 f \left( \begin{array}{cccc} 1 \\ 4 \\ 2 \\ 3 \\ \end{array} \right) = 1 + 4* x + 2 * x^2 + 3 * x^3

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

four 4 X 4 systems of equations.

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

For an example of row operations refer to previous problem solution. . .

Using row operations we obtain:

[ 1.0000 0.0000 0.0000 0.0000 3.1429 0.8571 1.2857 4.1429 0.0000 1.0000 0.0000 0.0000 2.2857 0.7857 0.0714 3.7857 0.0000 0.0000 1.0000 0.0000 1.4286 0.5714 0.1429 1.4286 0.0000 0.0000 0.0000 1.0000 0.1429 0.6429 0.2143 0.6429 ] \left[ \begin{array}{cccc|cccc} 1.0000 & 0.0000 & 0.0000 & 0.0000 & 3.1429 & 0.8571 & 1.2857 & 4.1429 \\ 0.0000 & 1.0000 & 0.0000 & 0.0000 & -2.2857 & 0.7857 & -0.0714 & -3.7857 \\ 0.0000 & 0.0000 & 1.0000 & 0.0000 & -1.4286 & -0.5714 & 0.1429 & -1.4286\\ 0.0000 & 0.0000 & 0.0000 & 1.0000 & 0.1429 & -0.6429 & -0.2143 & 0.6429\\ \ \end{array} \right]

\implies

M = [ 3.1429 0.8571 1.2857 4.1429 2.2857 0.7857 0.0714 3.7857 1.4286 0.5714 0.1429 1.4286 0.1429 0.6429 0.2143 0.6429 ] M = \begin{bmatrix}{3.1429} && {0.8571} && {1.2857} && {4.1429} \\ {-2.2857} && {0.7857} && {-0.0714} && {-3.7857} \\ {-1.4286} && {-0.5714} && {0.1429} && {-1.4286} \\ {0.1429} && {-0.6429} && {-0.2143} && {0.6429} \end{bmatrix}

and S = i = 1 4 j = 1 4 a i j = 0.7143 S = \sum_{i = 1}^{4} \sum_{j = 1}^{4} a_{i j} = \boxed{0.7143} .

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

Without using matrix M : M:

Let X = ( 1 3 7 5 ) X = \left( \begin{array}{cccc} 1 \\ 3\\ 7 \\ -5 \\ \end{array} \right)

\implies

f ( 1 3 7 5 ) = 1 + 3 x + 7 x 2 5 x 3 = α 1 ( 1 + x x 2 + x 3 ) + α 2 ( 1 x 2 ) + α 3 ( x 3 x 2 x 3 ) + α 4 ( 1 + 2 x 3 x 2 4 x 3 ) f \left( \begin{array}{cccc} 1 \\ 3 \\ 7 \\ -5 \\ \end{array} \right) = 1 + 3* x + 7 * x^2 - 5 * x^3 = \alpha_{1} * (1 + x - x^2 + x^3) + \alpha_{2} * (1 - x^2) + \alpha_{3} * (x - 3 * x^2 - x^3) + \alpha_{4} * (1 + 2 * x - 3 * x^2 - 4 * x^3)

= [ 1 1 0 1 1 0 1 2 1 1 3 3 1 0 1 4 ] α 1 α 2 α 3 α 4 = \begin{bmatrix}{1} && {1} && {0} && {1} \\ {1} && {0} && {1} && {2} \\ {-1} && {-1} && {-3} && {-3} \\ {1} && {0} && {-1} && {-4}\end{bmatrix} * \begin{vmatrix}{\alpha_{1}} \\{\alpha_{2}} \\ {\alpha_{3}} \\ {\alpha_{4}}\end{vmatrix}

Using the above we can set up the augmented matrix:

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

Using row operations on the above augmented matrix we obtain:

[ 1.0000 0.0000 0.0000 0.0000 1.8571 0.0000 1.0000 0.0000 0.0000 3.7143 0.0000 0.0000 1.0000 0.0000 4.5714 0.0000 0.0000 0.0000 1.0000 2.8571 ] \left[ \begin{array}{cccc|c} 1.0000 & 0.0000 & 0.0000 & 0.0000 & 1.8571\\ 0.0000 & 1.0000 & 0.0000 & 0.0000 & -3.7143 \\ 0.0000 & 0.0000 & 1.0000 & 0.0000 & -4.5714 \\ 0.0000 & 0.0000 & 0.0000 & 1.0000 & 2.8571\\ \ \end{array} \right]

\implies

[ f ( X ) ] B = ( 1.8571 3.7143 4.5714 2.8571 ) [f(X)]_{B} = \left( \begin{array}{ccccc} 1.8571\\ -3.7143\\ -4.5714\\ 2.8571\\ \end{array} \right)

Using matrix M M :

Using X = ( 1 3 7 5 ) X = \left( \begin{array}{cccc} 1 \\ 3\\ 7 \\ -5 \\ \end{array} \right) and basis A = { ( 1 2 3 4 ) , ( 1 1 2 4 ) , ( 1 1 1 2 ) , ( 1 4 2 3 ) } A = \{ \left( \begin{array}{cccc} 1 \\ 2 \\ 3 \\ 4 \\ \end{array} \right), \left( \begin{array}{cccc} 1 \\ -1 \\ 2 \\ 4 \\ \end{array} \right), \left( \begin{array}{cccc} 1 \\ 1 \\ -1 \\ 2 \\ \end{array} \right), \left( \begin{array}{cccc} 1 \\ 4 \\ 2 \\ 3 \\ \end{array} \right) \} for R 4 \mathbb R^4 \implies

X = ( 1 3 7 5 ) = β 1 ( 1 2 3 4 ) + β 2 ( 1 1 2 4 ) + β 3 ( 1 1 1 2 ) + β 4 ( 1 4 2 3 ) X = \left( \begin{array}{cccc} 1 \\ 3\\ 7 \\ -5 \\ \end{array} \right) = \beta_{1} * \left( \begin{array}{cccc} 1 \\ 2\\ 3 \\ 4 \\ \end{array} \right) + \beta_{2} * \left( \begin{array}{cccc} 1 \\ -1\\ 2 \\ 4 \\ \end{array} \right) + \beta_{3} * \left( \begin{array}{cccc} 1 \\ 1\\ -1 \\ 2 \\ \end{array} \right) + \beta_{4} * \left( \begin{array}{cccc} 1 \\ 4\\ 2 \\ 3 \\ \end{array} \right)

= [ 1 1 1 1 2 1 1 4 3 2 1 2 4 4 2 3 ] α 1 α 2 α 3 α 4 = \begin{bmatrix}{1} && {1} && {1} && {1} \\ {2} && {-1} && {1} && {4} \\ {3} && {2} && {-1} && {2} \\ {4} && {4} && {2} && {3}\end{bmatrix} * \begin{vmatrix}{\alpha_{1}} \\{\alpha_{2}} \\ {\alpha_{3}} \\ {\alpha_{4}}\end{vmatrix}

Using the above we can set up the augmented matrix:

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

Using row operations we obtain:

[ 1.0000 0.0000 0.0000 0.0000 163.0000 0.0000 1.0000 0.0000 0.0000 99.0000 0.0000 0.0000 1.0000 0.0000 56.0000 0.0000 0.0000 0.0000 1.0000 121.0000 ] \left[ \begin{array}{cccc|c} 1.0000 & 0.0000 & 0.0000 & 0.0000 & -163.0000 \\ 0.0000 & 1.0000 & 0.0000 & 0.0000 & 99.0000 \\ 0.0000 & 0.0000 & 1.0000 & 0.0000 & -56.0000 \\ 0.0000 & 0.0000 & 0.0000 & 1.0000 & 121.0000 \\ \ \end{array} \right]

[ X ] A = ( 163.0000 99.0000 56.0000 121.0000 ) \implies [X]_{A} = \left( \begin{array}{ccccc} -163.0000\\ 99.0000\\ -56.0000\\ 121.0000\\ \end{array} \right)

\implies

[ f ( X ) ] B = M [ X ] A = [ 3.1429 0.8571 1.2857 4.1429 2.2857 0.7857 0.0714 3.7857 1.4286 0.5714 0.1429 1.4286 0.1429 0.6429 0.2143 0.6429 ] ( 163.0000 99.0000 56.0000 121.0000 ) = ( 1.8571 3.7143 4.5714 2.8571 ) [f(X)]_B = M * [X]_A = \begin{bmatrix}{3.1429} && {0.8571} && {1.2857} && {4.1429} \\ {-2.2857} && {0.7857} && {-0.0714} && {-3.7857} \\ {-1.4286} && {-0.5714} && {0.1429} && {-1.4286} \\ {0.1429} && {-0.6429} && {-0.2143} && {0.6429} \end{bmatrix} * \left( \begin{array}{ccccc} -163.0000\\ 99.0000\\ -56.0000\\ 121.0000\\ \end{array} \right) = \left( \begin{array}{ccccc} 1.8571\\ -3.7143\\ -4.5714\\ 2.8571\\ \end{array} \right)

I used Free Pascal to write the program below:

program matrixrepresentaionoflineartransform_5;

{$R-}

{restricted to f:Rn --> P(n - 1)}

uses crt;

                                {self contained for brillant}

const maxnum = 100;

type matrix = array[1 .. maxnum,1 .. maxnum] of extended;

var

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

n,l,p,v:integer;

deta,detb,product:real;

f:matrix;{for me only-check}

mywork4:text;

function power(base:real; exponent:integer):real;

var n:integer;

product:real;

begin

product:= 1;

for n:= 1 to exponent do

product:= product * base;

power:= product;

end;

procedure Getsize;

begin

writeln('Enter n for Rn');

readln(n);

writeln('Number of polynomials of degree ',n - 1,' is ', n);

end;

procedure Getaugmatrix;

var k,q:integer;

sum:real;

begin

writeln('To Enter ', n, ' basis vectors for R',n,' : ');

for q:= 1 to n do

begin

write('Enter ',n,' elements of vector ', q, ' on one line: ');

for k:= 1 to n do

begin

read(b[k,q]);

end;

end;

writeln('To Enter ',n, ' polynomials of degree ', n - 1,' : ');

for q:= 1 to n do

begin

write('Enter ',n,' coefficients of polynomial ', q, ' on one line: ');

for k:= 1 to n do

begin

read(a[k,q]);

end;

end;

for q:= 1 to n do

begin

for k:= 1 to n do

begin

a[k,n + q]:= b[k,q];

end;

end;

writeln('Augmented matrix is:');

writeln;

for q:= 1 to n do

begin

for k:= 1 to 2 * n do

begin

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

end;

writeln;

end;

end;

{For check bases}

{begin}

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 Bases}

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 q:integer;

s:matrix;

begin{operation1}

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;{operation1}

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

var 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}

{end-check bases}

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

var q:integer;

z:real;

begin{switch}

for q:= 1 to 2 * n 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) <= 2 * n) 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 2 * n do

begin{m}

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

end;{m}

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

for q:= 1 to 2 * n do

begin{m}

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

end;{m}

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

writeln(mywork4);

for q:= 1 to n do

begin

for k:= 1 to 2 * n do

begin

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

end;

writeln(mywork4);

end;

writeln(mywork4);

end;{op1}

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

var q,r,k:integer;

x:real;

s:matrix;

begin{op2}

for q:= 1 to n do

begin{q}

if q <> l then

begin{then}

x:= a[q,l];

for r:= 1 to 2 * n do

begin{m}

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

end;{m}

for r:= 1 to 2 * n do

begin{m}

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

end;{m}

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

end;{then}

end;{q}

writeln(mywork4);

for q:= 1 to n do

begin

for k:= 1 to 2 * n do

begin

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

end;

writeln(mywork4);

end;

writeln(mywork4);

end;{op2}

PROCEDURE SHOWDATA;

VAR J,k:INTEGER;

sum:extended;

myfile2:text;

BEGIN

assign(myfile2,'holdsolution4.txt');

rewrite(myfile2);

writeln;

writeln('Matrix Representation of linear transformation f: R',n,' ---> P',n - 1,' : ');

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

writeln;

for j:= 1 to n do

begin

for k:= n + 1 to 2 * n do

begin

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

end;

writeln(myfile2);

end;

reset(myfile2);

for j:= 1 to n do

begin

for k:= 1 to n do

begin

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

end;

end;

close(myfile2);

for j:= 1 to n do

begin

for k:= 1 to n do

begin

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

end;

writeln;

end;

{For brillant only}

sum:= 0;

for j:= 1 to n do

begin

for k:= 1 to n do

begin

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

end;

end;

writeln;

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

END;

{Last check [f(x)]B }

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 + 1) 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: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(mywork4,y[q,n + 1]:0:4,'   ');

end;{q}

writeln(mywork4);

end;{solution}

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

var j,k,s:integer;

   sum:extended;

begin{matrixmult}

for j:= 1 to n do

begin{j}

for k:= 1 to 1 do

begin{k}

     sum:= 0;

for s:= 1 to n do

begin{s}

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

end;{s}

      summat[j,k]:= sum;

              end;{k}

writeln(mywork4,sum:0:4);

end;{j}

writeln(mywork4);

end;{matrixmult}

procedure check;

var p,j,k:integer;

sum:real;

u:matrix;

begin

{without using matrix}

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

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

writeln(mywork4);

writeln('Enter a vector in R',n,' on one line');

for j:= 1 to n do

begin

read(f[j,n + 1]);

end;

for j:= 1 to n do

begin

e[j,n + 1]:= f[j,n + 1];

end;

for j:= 1 to n do

begin

for k:= 1 to n + 1 do

begin

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

end;

writeln(mywork4);

end;

{Next Use operations on matrix f}

writeln(mywork4);

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

writeln(mywork4);

for l:= 1 to n do

begin{l}

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

if v = 0 then

begin{then}

operation13(f,l,n);

operation23(f,l,n);

end;{then}

end;{l}

writeln(mywork4);

solution(f,n);

{Now do using matrix M}

writeln(mywork4);

writeln(mywork4);

for j:= 1 to n do

begin

for k:= 1 to n + 1 do

begin

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

end;

writeln(mywork4);

end;

for l:= 1 to n do

begin{l}

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

if v = 0 then

begin{then}

operation13(e,l,n);

operation23(e,l,n);

end;{then}

end;{l}

writeln(mywork4);

solution(e,n);

writeln(mywork4);

writeln(mywork4);

for j:= 1 to n do

begin

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

end;

writeln(mywork4);

writeln(mywork4);

matrixmult(sol,u,prod);

end;

begin

assign(mywork4,'mywork4.txt');

rewrite(mywork4);

getsize;

getaugmatrix;

hold(f,a,n); {for me only-check [f(X)]}

hold(e,b,n);

{do determinants here}

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

{checking basis for Rn}

PRODUCT:= 1;

for l:= 1 to n do

begin{l}

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

if v = 0 then

begin{then}

operation11(b,l,n,PRODUCT);

operation21(b,l,n);

end;{then}

end;{l}

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

writeln(detb:0:20);

while (detb >= 0) and (detb <= abs(power(1/10,16))) do {I.E; detb ~ 0}

begin

writeln('Set of matrices is not a basis for R',n);

writeln;

getaugmatrix;

PRODUCT:= 1;

for l:= 1 to n do

begin{l}

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

if v = 0 then

begin{then}

operation11(b,l,n,PRODUCT);

operation21(b,l,n);

end;{then}

end;{l}

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

end;

{checking basis for Rn^2}

hold(c,a,n);

PRODUCT:= 1;

for l:= 1 to n do

begin{l}

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

if v = 0 then

begin{then}

operation11(c,l,n,PRODUCT);

operation21(c,l,n);

end;{then}

end;{l}

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

writeln;

while (deta >= 0) and (deta <= abs(power(1/10,16))) do {I.E; deta ~ 0}

begin

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

writeln;

getaugmatrix;

hold(c,a,n);

PRODUCT:= 1;

for l:= 1 to n do

begin{l}

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

if v = 0 then

begin{then}

operation11(c,l,n,PRODUCT);

operation21(c,l,n);

end;{then}

end;{l}

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

end;

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

for l:= 1 to n 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;

close(mywork4);

readln;

readln;

end.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...