S
sensorflo
Hello
I would like to apply a formula operating on matrices/vectors to a
number of rows.
Formula:
T1*(v1+T2*v2)
Input:
T1 is a 2x2 Matrix, v1 a 2x1 vector, both are defined through cells
which are always at the same location within the Worksheet. For example
T1 in A1:B2, v1 in A3:B3.
T2 is a 2x2 Matrix defined by { cos(x),sin(x); -sin(x),cos(x)}.
x is a value, v2 a 2x1 vector. See below how they are defined
Output:
A 2x1 vector
Task:
I now want to apply the formula to a number of rows. In each row the
column 1 to 2 define v2, column 3 defines x. The result of the formula
should be in column 4 and 5.
How would you do that? Thank you for your help
Florian Kaufmann
Its not that I want you to do my work without trying myself first.
That's what I tried so far
My first try:
---------------
I gave the name T1 to the range A1:B2, v1 to A3:B3.
In A4:B4 is v2, in C4 is x.
In C5 I put
=INDEX( MMULT( T1 ; v1 + MMULT( {cos(C4),sin(C4); -sin(C4),cos(C4)};
A4:B4 ) ) ; 1 )
In C6 I put
=INDEX( MMULT( T1 ; v1 + MMULT( {cos(C4),sin(C4); -sin(C4),cos(C4)};
A4:B4 ) ) ; 2 )
However, it turns out that a construct like {cos(C4),sin(C4);
-sin(C4),cos(C4)} is not possible, since arrays of type {...} must be
constant. They can not contain references to cells as I did with C4.
Second try:
------------
I tried to write a VB Function which does the job. But since I am an
absolute beginner in VB, I have various troubles.
- How to call my function from a cell. I always get "#Name?"
- How to define T2 within the function
- There seems to be a different between Ranges and Arrays, and I don't
know where it is. I get errors passing ranges to mmult.
I would like to apply a formula operating on matrices/vectors to a
number of rows.
Formula:
T1*(v1+T2*v2)
Input:
T1 is a 2x2 Matrix, v1 a 2x1 vector, both are defined through cells
which are always at the same location within the Worksheet. For example
T1 in A1:B2, v1 in A3:B3.
T2 is a 2x2 Matrix defined by { cos(x),sin(x); -sin(x),cos(x)}.
x is a value, v2 a 2x1 vector. See below how they are defined
Output:
A 2x1 vector
Task:
I now want to apply the formula to a number of rows. In each row the
column 1 to 2 define v2, column 3 defines x. The result of the formula
should be in column 4 and 5.
How would you do that? Thank you for your help
Florian Kaufmann
Its not that I want you to do my work without trying myself first.
That's what I tried so far
My first try:
---------------
I gave the name T1 to the range A1:B2, v1 to A3:B3.
In A4:B4 is v2, in C4 is x.
In C5 I put
=INDEX( MMULT( T1 ; v1 + MMULT( {cos(C4),sin(C4); -sin(C4),cos(C4)};
A4:B4 ) ) ; 1 )
In C6 I put
=INDEX( MMULT( T1 ; v1 + MMULT( {cos(C4),sin(C4); -sin(C4),cos(C4)};
A4:B4 ) ) ; 2 )
However, it turns out that a construct like {cos(C4),sin(C4);
-sin(C4),cos(C4)} is not possible, since arrays of type {...} must be
constant. They can not contain references to cells as I did with C4.
Second try:
------------
I tried to write a VB Function which does the job. But since I am an
absolute beginner in VB, I have various troubles.
- How to call my function from a cell. I always get "#Name?"
- How to define T2 within the function
- There seems to be a different between Ranges and Arrays, and I don't
know where it is. I get errors passing ranges to mmult.