Effacer les filtres
Effacer les filtres

How to iteratively multiply a vector by a matrix iteratively

2 vues (au cours des 30 derniers jours)
Andrew Poissant
Andrew Poissant le 16 Fév 2017
I want to multiply an initial vector p_t0 by a matrix P. The vector and matrix are specified below. If I simply do p = p_t0*P I get my first set of answers which is what I want but I want to repeat the procedure 50 times (for t=[1 50]). Any ideas on how I can do this? I attempted it below but kept getting an error saying "the number of elements in A and B must be the same."
h = 0.5;
u = 0.3;
P = [1-h h 0 0 0 ; ...
u 1-h-u h 0 0; ...
0 u 1-h-u h 0; ...
0 0 u 1-h-u h; ...
0 0 0 u 1-u;];
%Initialize initial probability vector
p0_t0 = 0.2;
p1_t0 = 0.2;
p2_t0 = 0.2;
p3_t0 = 0.2;
p4_t0 = 0.2;
p_t0 = [p0_t0 p1_t0 p2_t0 p3_t0 p4_t0];
p = p_t0*P %initial vector produced at time of 0
tf = 50
for t = 2:tf+1
p(1) = p_t0*P
p(t) = p(t-1)*P;
end

Réponse acceptée

Roger Stafford
Roger Stafford le 16 Fév 2017
The the product p_t0*P produces a five-element vector so you should write:
......
p = zeros(tf,5); % <-- for more efficient allocation
p(1,:) = p_t0*P;
for t = 2:tf
p(t,:) = p(t-1,:)*P;
end

Plus de réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by