matrix operations and vectorization

1 view (last 30 days)
msh
msh on 25 Apr 2015
Edited: Stephen23 on 25 Apr 2015
Hi I would like a little help to construct in Matlab a fast way of carrying out the following computations.
Suppose that there are T simulation periods and t is the period of the simulation. In each period I compute the elements of three vectors u1, u2, u3 all vectors are of size (T,1). I also have a known row vector x = [A(t-5:t-1)' 1 kh(t-5:t-1)'] produced in every iteration (period t).
I would like to compute what is described describe in the attached picture. That is all the possible combinations (product terms) for each element of the vectors u's in each iteration period.
Can someone help me implement this on Matlab?
  2 Comments
Stephen23
Stephen23 on 25 Apr 2015
The equation shown in the image does not mention u1, u2 or u3 anywhere, so it is not clear what these are used for.
msh
msh on 25 Apr 2015
Edited: msh on 25 Apr 2015
Apologies for the confusion,
So let me explain then, that the image shows m different vectors epsilon of length(T), that is the length of the simulation, in my case u1 = epsilon1, so the element of each vector, say the first one, is u1(t)=e1(t) where t is the iteration point.
so in each iteration I want to compute the different products and cross products of the elements of these three different vectors.
I hope now is more clear.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 25 Apr 2015
Edited: Stephen23 on 25 Apr 2015
You can generate the terms in the matrix very easily using bsxfun:
>> a = [1,2,3];
>> b = [1,2,3,4];
>> bsxfun(@times, a(:), b)
ans =
1 2 3 4
2 4 6 8
3 6 9 12
Note that the orientation of the input vectors/matrices is significant. Then you can simply sum over the T values, which you seem to be generating in a loop.
  3 Comments
Stephen23
Stephen23 on 25 Apr 2015
Edited: Stephen23 on 25 Apr 2015
As far as I can see the equation references an epsilon vector, and creates a matrix from this. Why do you want to multiply these three matrices together?
msh
msh on 25 Apr 2015
Edited: msh on 25 Apr 2015
I see your point, but the image implies an m different epsilon vectors. In my question I have m=3, and the correponding epsilon vectors are the u1,u2, u3.
I understood how I can get the corresponding matrix of the image if there are two vectors but I am confused on how I can use the command you suggested when there are more than two vectors in order to produce the corresponding matrix.
otherwise I am thinking of this:
u = [ u1 u2 u3] , where size(u1)=size(u2)=size(u3)
bsxfun(@times, u(:), u)
Then I should get the matrix of the image or no?

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!