COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Linear combination between lines of a matrix

• Email
• Follow

```Hi,

Is it possible to quickly modify a given matrix A so that for example, if L1
(resp. L3) represents the first line (resp. the third line) of A.

L2 <- 4/5*L2 + 2/3*L1

If it is possible, how can I do that ?

Thanks for any help,

Robert Derochette
```
 0

See related articles to this posting

``` > L2 <- 4/5*L2 + 2/3*L1

Assuming A is a 3x3 matrix,
A = B*A should do the job if
[ 1   0  0]
B=[2/3 4/5 0]
[ 0   0  1]

Does that help?

Later,
Daniel
```
 0

```Daniel Herring wrote:

>  > L2 <- 4/5*L2 + 2/3*L1
>
> Assuming A is a 3x3 matrix,
> A = B*A should do the job if
>    [ 1   0  0]
> B=[2/3 4/5 0]
>    [ 0   0  1]
>
> Does that help?
>
> Later,
> Daniel

Well that doesn't seem to work whith rectangular matrixes. Well, let me
explain what I mean. In my case the matrix A represents a linear homogen
system of equations, i.e.

|  1  7  6 | 0 |
A=| -5  5 -1 | 0 |
|  0  0  0 | 0 |

The goal is finding non trivial solutions of this system. In order to do
this I must first change A to its normal form. In this case, A is obviously
of rank 2. So a should become something like

| 1  0 e1 | 0 |
A'=| 0  1 e2 | 0 |
| 0  0  0 | 0 |

So the non trivial solution would be

| e1 |
k*| e2 | , k constant
|  1 |

That's why I need to be able to do linear combinations between the lines of
a rectangular matrix. Maybe there is a built-in function to do this but the
numeric solver is *not* the way to go if you want to solve a system this
way ...

Thanks for any help

Robert Derochette

PS : (Note to Daniel Herring) Maybe your method of a left multiplication by
a square matrix should also be able to solve my problem. But then I'm too
dumb to find what elements I have to put in my matrix ;-).
```
 0

```Duh, I should use my brain before posting here. For the problem I exposed
earlier, the easy way to solve it is (if anyone interested)

|  1  7  6 |
A = | -5  5 -1 |
|  0  0  0 |

So the same matrix without the column of zeros on the right.
Now that your matrix A is on top of the stack, just do EGV. Sure the non
trivial solution of the system Ax = 0 is the eigen vector of A ... Note
that the HP49 will output a matrix containing three eigen vectors, only
consider the one with only real elements.

Robert Derochette

```
 0

```Daniel Herring wrote:

>  > L2 <- 4/5*L2 + 2/3*L1
>
> Assuming A is a 3x3 matrix,
> A = B*A should do the job if
>    [ 1   0  0]
> B=[2/3 4/5 0]
>    [ 0   0  1]
>
> Does that help?
>
> Later,
> Daniel

I've solved my particular problem as it was in fact an eigen vectors
problem. But anyway it would be useful if I could do linear combinations
between the lines of a (not necessarily square) matrix. Any idea how I
could do that ?

Thanks

Robert Derochette
```
 0

``` > ... it would be useful if I could do linear combinations
> between the lines of a (not necessarily square) matrix.

While you could write a special-purpose program to do this,
matrix-multiplication is (after some practice) more natural for linear
manipulations.

First, define the identity matrix.  The identity matrix is simply full
of 0's, with 1's on the diagonal.
1x1 identity matrix:
I = [ 1 ]

2x2 identity matrix:
I = [ 1 0 ]
[ 0 1 ]

3x3 identity matrix:
[ 1 0 0 ]
I = | 0 1 0 |
[ 0 0 1 ]

On the 49G+, the NxN identity matrix may be generated by entering N on
the stack and pressing
keys "<-" "MTH" and menus "MATRX" "MAKE" "IDN".

Multiplying an NxN identity matrix by any NxM matrix will return the NxM
matrix unchanged.
(Note: Matrices are denoted by (# of rows)x(# of columns).  This follows
from the convention for numbering elements.)

So for a 3x4 matrix,
[ 1 2 3 4 ]
A = | 5 6 7 8 |
[ 9 0 1 2 ]

I(3x3) * A => A

***** Row Manipulations *****
Given A is a NxM matrix, create I(NxN).
To change the i-th row of A, simply modify the i-th row of I.
The term in the j-th column of this row will multiply the j-th row of A.
Then, all these multiples will be summed together.

If I want (row) A3 = k1 A1 + k2 A2 + k3 A3, then let
[  1  0  0 ]
B = |  0  1  0 |
[ k1 k2 k3 ]
and B * A gives the desired answer.

If you are experiencing "Invalid Dimension" errors, then you probably
have the matrices on the stack in the wrong order.

***** Column manipulations *****
Changing the columns requires only a simple modification to the above
procedure.  In short, change the dimension of I and reverse the order of
multiplication.

Given A is a NxM matrix, create I(MxM).
To change the j-th column of A, simply modify the j-th column of I.
The term in the i-th row of this column will multiply the i-th column of
A.  Then, all these multiples will be summed together.

If I want (column) A2 = k1 A1 + k2 A2 + k3 A3 + k4 A4, then let
[  1 k1  0  0 ]
B = |  0 k2  0  0 |
|  0 k3  1  0 |
[  0 k4  0  1 ]
and A * B gives the desired answer.

Hope that helps,
Daniel
```
 0

```Robert Derochette wrote:
> Hi,
>
> Is it possible to quickly modify a given matrix A so that for example, if L1
> (resp. L3) represents the first line (resp. the third line) of A.
>
>     L2 <- 4/5*L2 + 2/3*L1
>
> If it is possible, how can I do that ?

I'm not sure if the 48G series has theses commands, but the 49G has them...
use RCI and RCIJ. For your example it would be

'4/5' 2 RCI '2/3' 1 2 RCIJ

and you'll get your desired result...

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.
```
 0

```> Hope that helps,
> Daniel

Yes it helped. Now I still need some training in order not to make stupid
mistakes, but hell yes this method is fast :). Thanks very much.

Robert Derochette
```
 0

```In article <41078f1b\$0\$1242\$ba620e4c@news.skynet.be>,
Robert Derochette <lord_rob26@DONOTSPAMsofthome.net> wrote:

> Well that doesn't seem to work whith rectangular matrixes. Well, let me
> explain what I mean. In my case the matrix A represents a linear homogen
> system of equations, i.e.
>
>   |  1  7  6 | 0 |
> A=| -5  5 -1 | 0 |
>   |  0  0  0 | 0 |
>
> The goal is finding non trivial solutions of this system. In order to do
> this I must first change A to its normal form. In this case, A is obviously
> of rank 2. So a should become something like
>
>    | 1  0 e1 | 0 |
> A'=| 0  1 e2 | 0 |
>    | 0  0  0 | 0 |

To go from A to A' in one step, use the built in command RREF, which
returns the row reduced echelon form (rref) of a given matrix, on all
48's and 49's. On the 49's it can give exact results for an exact input
matrix.

I found that, in exact mode on my 49+,

[[  1  7  6  0]
[ -5  5 -1  0]
[  0  0  0  0 ]]

RREF

returned

[[ 1 0 '37/40' 0]
[ 0 1 '29/40' 0]
[ 0 0    0    0]]

Is this what you want?
```
 0

```> RREF
>
> returned
>
> [[ 1 0 '37/40' 0]
>  [ 0 1 '29/40' 0]
>  [ 0 0    0    0]]
>
> Is this what you want?

Yes this also works this way. Replacing the 0 behind the '29/40' by a 1 also
gives the correct non-trivial solution of the problem

Thanks
```
 0

```Robert Derochette wrote:

>> RREF
>>
>> returned
>>
>> [[ 1 0 '37/40' 0]
>>  [ 0 1 '29/40' 0]
>>  [ 0 0    0    0]]
>>
>> Is this what you want?
>
> Yes this also works this way. Replacing the 0 behind the '29/40' by a 1

Errm, you must replace the 0 behind the '29/40' by a -1 and *not* a 1. I
should really relearn some basic algebra :-/.
```
 0

```Robert Derochette wrote:

> Hi,
>
> Is it possible to quickly modify a given matrix A so that for example, if L1
> (resp. L3) represents the first line (resp. the third line) of A.
>
>     L2 <- 4/5*L2 + 2/3*L1
>
> If it is possible, how can I do that ?
>
There's a way..
using a small RPL program.

<< AXL -> L << 'L(2)' EVAL 4 * 5 / L(1) EVAL 2 * 3 / 'L(2)' STO L AXL >>

Jean-Yves

```
 0