Info
This question is closed. Reopen it to edit or answer.
How do I create such matrix ? (please look at the thread for further details)
2 views (last 30 days)
Show older comments
Hi,
Let say I have a matrix [ X1 X2 X3 .... Xm]
I need to use a method base on X1, X2 and X3 to get my X4, X5 till Xm.
The method in order to find X4 is X4=(X1+X2+X3)/3. Once X4 is calculated, we use the X4 to calculate X5 which now the it will turn out to be X5=(X2+X3+X4)/3 and find X6 using the found X5 and X4, X6=(X3+X4+X5)/3 and so on until we find Xm.
My question is, how do we come out with such matrix ?
0 Comments
Answers (3)
Walter Roberson
on 19 Dec 2013
X = rand(1,3);
for K = 4 : m
X(K) = mean(X(K-3:K-1));
end
2 Comments
Walter Roberson
on 21 Dec 2013
Do you mean the case where X4 and X5 have already been found, so you want to continue on from X6 ? But 4 is not (1 + 2 + 3)/3 ?
If it is the question of how to do this for several rows simultaneously, then
X = rand(2,3); %example 2 rows
for K = 4 : m
X(:,K) = mean(X(:,K-3:K-1),2);
end
Andrei Bobrov
on 19 Dec 2013
Edited: Andrei Bobrov
on 19 Dec 2013
X = randi(25,1,10);
n = 3;
X = X(:);
X = [X(1:n);conv2(X(1:end-n+2),ones(n,1)/n,'valid')];
on Deric's comment
X = randi(1500,93,343);
n = 3;
X = [X(:,1:n), conv2(X(:,1:end-n+2),ones(1,n)/n,'valid')];
2 Comments
Roger Stafford
on 21 Dec 2013
In case it is of interest to you, Derick, here is an explicit formula for individual elements of your vector X in terms of its first three elements. That is, it doesn't involve iteration - one can find the n-th element without evaluating others.
Let x1, x2, and x3 be the first three elements.
a = (x1+2*x2+3*x3)/6;
b = (-x1+4*x2-3*x3)/6;
c = (-2*x1-x2+3*x3)/3/sqrt(2);
t = atan2(sqrt(2),-1);
X(n) = a+3^(-(n-2)/2)*(b*cos((n-2)*t)+c*sin((n-2)*t));
This shows that X consists of rather widely-spaced points in an exponentially decaying sine function.
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!