How to apply Loop Function to this example

1 visualización (últimos 30 días)
Yaser Kishawi
Yaser Kishawi el 20 de Sept. de 2020
Comentada: Yaser Kishawi el 20 de Sept. de 2020
Hi All,
I doing a matrix x vector multiplcation where the output of the first step is a vector that will be mltiplied with the same matrix in the next step and the step need to be repeated 10 times, I have done the following code which I know is primitve. Can you help me to make a s for loop where I repeat the clculation 10 times
clc;
clear all;
format longE
i=0
M = [.93 .05; .07 .95]
x0 = [800000; 600000]
x1=M*x0
x2=M*x1
x3=M*x2
x4=M*x3
x5=M*x4
x6=M*x5
x7=M*x6
x8=M*x7
x9=M*x8
x10=M*x9

Respuesta aceptada

Matt J
Matt J el 20 de Sept. de 2020
Editada: Matt J el 20 de Sept. de 2020
x=x0;
for i=1:10
x=M*x;
end
  1 comentario
Yaser Kishawi
Yaser Kishawi el 20 de Sept. de 2020
I know if I removed the ; it will give me the vector for each iteration, but it will display it as x = [ the result].
Can I display an increment x value (i.e. x1 = the results, then x2 = the new results, until x10 = the final results)?
Thanks in advance

Iniciar sesión para comentar.

Más respuestas (1)

Ameer Hamza
Ameer Hamza el 20 de Sept. de 2020
Or without loop
x = M^10*x0;

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by