How do I create such matrix ? (please look at the thread for further details)
Info
This question is closed. Reopen it to edit or answer.
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 ?
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
Derick Wong
on 19 Dec 2013
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
Derick Wong
on 19 Dec 2013
Andrei Bobrov
on 19 Dec 2013
see in my answer code after row with "on Deric ..."
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.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!