Dina

20 Reputation

2 Badges

9 years, 140 days

MaplePrimes Activity


These are replies submitted by Dina

@Carl Love 

I want to keep the matrix A to be itself

and ceareet new matrix c which has the first column in A

I meen I want to change the first column in the matrix A by the column b and call the new matrix is c

restart

with(linalg):

A := Matrix([[1, -1, 2, -1], [2, -2, 3, -3], [1, 1, 1, 0], [1, -1, 4, 3]])

A := Matrix(4, 4, {(1, 1) = -8, (1, 2) = -1, (1, 3) = 2, (1, 4) = -1, (2, 1) = -20, (2, 2) = -2, (2, 3) = 3, (2, 4) = -3, (3, 1) = -2, (3, 2) = 1, (3, 3) = 1, (3, 4) = 0, (4, 1) = 4, (4, 2) = -1, (4, 3) = 4, (4, 4) = 3})

(1)

b := Vector([-8, -20, -2, 4])

b := Vector(4, {(1) = -8, (2) = -20, (3) = -2, (4) = 4})

(2)

if Determinant(A) = 0 then no*unique*solution*exists end if;

4.

(3)

n := 4;

4

(4)

A[() .. (), 1] := b

A[() .. (), 1] := Vector(4, {(1) = -8, (2) = -20, (3) = -2, (4) = 4})

(5)

evalm(A)

array( 1 .. 4, 1 .. 4, [( 2, 2 ) = (-2), ( 4, 4 ) = (3), ( 1, 2 ) = (-1), ( 4, 3 ) = (4), ( 2, 3 ) = (3), ( 4, 1 ) = (4), ( 4, 2 ) = (-1), ( 1, 1 ) = (-8), ( 3, 4 ) = (0), ( 2, 4 ) = (-3), ( 2, 1 ) = (-20), ( 1, 3 ) = (2), ( 3, 2 ) = (1), ( 1, 4 ) = (-1), ( 3, 3 ) = (1), ( 3, 1 ) = (-2)  ] )

(6)

A

Matrix([[-8, -1, 2, -1], [-20, -2, 3, -3], [-2, 1, 1, 0], [4, -1, 4, 3]])

(7)

C := Matrix([A[() .. (), 1] = b])

C := Matrix(1, 1, {(1, 1) = (Vector(4, {(1) = -8, (2) = -20, (3) = -2, (4) = 4})) = (Vector(4, {(1) = -8, (2) = -20, (3) = -2, (4) = 4}))})

(8)

``

``

 

Download try_2_cram.mw

dinaalrehaili_(1).mw

restart

with(linalg):

A := Matrix([[1, -1, 2, -1], [2, -2, 3, -3], [1, 1, 1, 0], [1, -1, 4, 3]])

A := Matrix(4, 4, {(1, 1) = 1, (1, 2) = -1, (1, 3) = 2, (1, 4) = -1, (2, 1) = 2, (2, 2) = -2, (2, 3) = 3, (2, 4) = -3, (3, 1) = 1, (3, 2) = 1, (3, 3) = 1, (3, 4) = 0, (4, 1) = 1, (4, 2) = -1, (4, 3) = 4, (4, 4) = 3})

(1)

b := Vector([-8, -20, -2, 4])

b := Vector(4, {(1) = -8, (2) = -20, (3) = -2, (4) = 4})

(2)

if Determinant(A) = 0 then no*unique*solution*exists end if;

4.

(3)

n := 4:

AA := Matrix(augment(A, b))

AA := Matrix(4, 5, {(1, 1) = 1, (1, 2) = -1, (1, 3) = 2, (1, 4) = -1, (1, 5) = -8, (2, 1) = 2, (2, 2) = -2, (2, 3) = 3, (2, 4) = -3, (2, 5) = -20, (3, 1) = 1, (3, 2) = 1, (3, 3) = 1, (3, 4) = 0, (3, 5) = -2, (4, 1) = 1, (4, 2) = -1, (4, 3) = 4, (4, 4) = 3, (4, 5) = 4})

(4)

AA

Matrix([[1, -1, 2, -1, -8], [2, -2, 3, -3, -20], [1, 1, 1, 0, -2], [1, -1, 4, 3, 4]])

(5)

for i to n-1 do for j from i+1 to n do if AA[1, 1] = 0 then if AA[j, 1] = 0 then AA := RowOperation(AA, [1, j+1]) else AA := RowOperation(AA, [1, j]) end if end if end do end do; evalm(AA)

array( 1 .. 4, 1 .. 5, [( 4, 3 ) = (4), ( 2, 1 ) = (2), ( 1, 4 ) = (-1), ( 3, 5 ) = (-2), ( 3, 1 ) = (1), ( 4, 4 ) = (3), ( 1, 1 ) = (1), ( 3, 4 ) = (0), ( 1, 5 ) = (-8), ( 1, 2 ) = (-1), ( 2, 4 ) = (-3), ( 2, 5 ) = (-20), ( 4, 5 ) = (4), ( 4, 1 ) = (1), ( 3, 3 ) = (1), ( 1, 3 ) = (2), ( 2, 3 ) = (3), ( 2, 2 ) = (-2), ( 4, 2 ) = (-1), ( 3, 2 ) = (1)  ] )

(6)

for i to n-1 do for j from i+1 to n do if AA[i, i] <> 0 then m := -AA[j, i]/AA[i, i]; AA := RowOperation(AA, [j, i], m) else AA := RowOperation(AA, [j, i]) end if end do end do; evalm(AA)

array( 1 .. 4, 1 .. 5, [( 4, 3 ) = (0), ( 2, 1 ) = (0), ( 1, 4 ) = (-1), ( 3, 5 ) = (-4), ( 3, 1 ) = (0), ( 4, 4 ) = (2), ( 1, 1 ) = (1), ( 3, 4 ) = (-1), ( 1, 5 ) = (-8), ( 1, 2 ) = (-1), ( 2, 4 ) = (1), ( 2, 5 ) = (6), ( 4, 5 ) = (4), ( 4, 1 ) = (0), ( 3, 3 ) = (-1), ( 1, 3 ) = (2), ( 2, 3 ) = (-1), ( 2, 2 ) = (2), ( 4, 2 ) = (0), ( 3, 2 ) = (0)  ] )

(7)

if A[n, n] = 0 then no*unique*solution*exists end if; evalm(AA)

array( 1 .. 4, 1 .. 5, [( 4, 3 ) = (0), ( 2, 1 ) = (0), ( 1, 4 ) = (-1), ( 3, 5 ) = (-4), ( 3, 1 ) = (0), ( 4, 4 ) = (2), ( 1, 1 ) = (1), ( 3, 4 ) = (-1), ( 1, 5 ) = (-8), ( 1, 2 ) = (-1), ( 2, 4 ) = (1), ( 2, 5 ) = (6), ( 4, 5 ) = (4), ( 4, 1 ) = (0), ( 3, 3 ) = (-1), ( 1, 3 ) = (2), ( 2, 3 ) = (-1), ( 2, 2 ) = (2), ( 4, 2 ) = (0), ( 3, 2 ) = (0)  ] )

(8)

x[n] := AA[n, n+1]/AA[n, n];

2

(9)

u := 0;

0

(10)

for i to n-1 do for j from n-i+1 to n do v := AA[n-i, j]*x[j]+u end do; x[n-i] := (AA[n-i, n+1]-v)/AA[n-i, n-i] end do;

2

 

2

 

-6

(11)

``



Download dinaalrehaili_(1).mwdinaalrehaili_(1).mw

restart

with(linalg):

A := Matrix([[1, -1, 2, -1], [2, -2, 3, -3], [1, 1, 1, 0], [1, -1, 4, 3]])

A := Matrix(4, 4, {(1, 1) = 1, (1, 2) = -1, (1, 3) = 2, (1, 4) = -1, (2, 1) = 2, (2, 2) = -2, (2, 3) = 3, (2, 4) = -3, (3, 1) = 1, (3, 2) = 1, (3, 3) = 1, (3, 4) = 0, (4, 1) = 1, (4, 2) = -1, (4, 3) = 4, (4, 4) = 3})

(1)

b := Vector([-8, -20, -2, 4])

b := Vector(4, {(1) = -8, (2) = -20, (3) = -2, (4) = 4})

(2)

if Determinant(A) = 0 then no*unique*solution*exists end if;

4.

(3)

n := 4:

AA := Matrix(augment(A, b))

AA := Matrix(4, 5, {(1, 1) = 1, (1, 2) = -1, (1, 3) = 2, (1, 4) = -1, (1, 5) = -8, (2, 1) = 2, (2, 2) = -2, (2, 3) = 3, (2, 4) = -3, (2, 5) = -20, (3, 1) = 1, (3, 2) = 1, (3, 3) = 1, (3, 4) = 0, (3, 5) = -2, (4, 1) = 1, (4, 2) = -1, (4, 3) = 4, (4, 4) = 3, (4, 5) = 4})

(4)

AA

Matrix([[1, -1, 2, -1, -8], [2, -2, 3, -3, -20], [1, 1, 1, 0, -2], [1, -1, 4, 3, 4]])

(5)

for i to n-1 do for j from i+1 to n do if AA[1, 1] = 0 then if AA[j, 1] = 0 then AA := RowOperation(AA, [1, j+1]) else AA := RowOperation(AA, [1, j]) end if end if end do end do; evalm(AA)

array( 1 .. 4, 1 .. 5, [( 4, 3 ) = (4), ( 2, 1 ) = (2), ( 1, 4 ) = (-1), ( 3, 5 ) = (-2), ( 3, 1 ) = (1), ( 4, 4 ) = (3), ( 1, 1 ) = (1), ( 3, 4 ) = (0), ( 1, 5 ) = (-8), ( 1, 2 ) = (-1), ( 2, 4 ) = (-3), ( 2, 5 ) = (-20), ( 4, 5 ) = (4), ( 4, 1 ) = (1), ( 3, 3 ) = (1), ( 1, 3 ) = (2), ( 2, 3 ) = (3), ( 2, 2 ) = (-2), ( 4, 2 ) = (-1), ( 3, 2 ) = (1)  ] )

(6)

for i to n-1 do for j from i+1 to n do if AA[i, i] <> 0 then m := -AA[j, i]/AA[i, i]; AA := RowOperation(AA, [j, i], m) else AA := RowOperation(AA, [j, i]) end if end do end do; evalm(AA)

array( 1 .. 4, 1 .. 5, [( 4, 3 ) = (0), ( 2, 1 ) = (0), ( 1, 4 ) = (-1), ( 3, 5 ) = (-4), ( 3, 1 ) = (0), ( 4, 4 ) = (2), ( 1, 1 ) = (1), ( 3, 4 ) = (-1), ( 1, 5 ) = (-8), ( 1, 2 ) = (-1), ( 2, 4 ) = (1), ( 2, 5 ) = (6), ( 4, 5 ) = (4), ( 4, 1 ) = (0), ( 3, 3 ) = (-1), ( 1, 3 ) = (2), ( 2, 3 ) = (-1), ( 2, 2 ) = (2), ( 4, 2 ) = (0), ( 3, 2 ) = (0)  ] )

(7)

if A[n, n] = 0 then no*unique*solution*exists end if; evalm(AA)

array( 1 .. 4, 1 .. 5, [( 4, 3 ) = (0), ( 2, 1 ) = (0), ( 1, 4 ) = (-1), ( 3, 5 ) = (-4), ( 3, 1 ) = (0), ( 4, 4 ) = (2), ( 1, 1 ) = (1), ( 3, 4 ) = (-1), ( 1, 5 ) = (-8), ( 1, 2 ) = (-1), ( 2, 4 ) = (1), ( 2, 5 ) = (6), ( 4, 5 ) = (4), ( 4, 1 ) = (0), ( 3, 3 ) = (-1), ( 1, 3 ) = (2), ( 2, 3 ) = (-1), ( 2, 2 ) = (2), ( 4, 2 ) = (0), ( 3, 2 ) = (0)  ] )

(8)

x[n] := AA[n, n+1]/AA[n, n];

2

(9)

u := 0;

0

(10)

for i to n-1 do for j from n-i+1 to n do v := AA[n-i, j]*x[j]+u end do; x[n-i] := (AA[n-i, n+1]-v)/AA[n-i, n-i] end do;

2

 

2

 

-6

(11)

``


Download dinaalrehaili_(1).mw

@tomleslie 

dinaalrehaili_(1).mw

the exact solution is x4=2

x3=2

x2=2

x1=-7

 

the proplem in j loop I think 

dinaalrehaili.mw

 

he is substitute for k just k=1
i want from him substitute for k three times
k=3, k=2 and k=1
to get x[3] , x[2] and x[1]
i hope you understand me
thank you very much

Page 1 of 1