How to iteratively multiply a vector by a matrix iteratively
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Andrew Poissant
el 16 de Feb. de 2017
Respondida: Roger Stafford
el 16 de Feb. de 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
0 comentarios
Respuesta aceptada
Roger Stafford
el 16 de Feb. de 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
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!