How to fill a matrix with formulas
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi
I have a matrix as follows:
I want to fill this matrix (4,5) whose first member is y (1,1) = 0.4 using the formula
y (i) = 2 * y (i-1) * (1-y (i-1))
Please write the source for me.
2 comentarios
John D'Errico
el 8 de Sept. de 2021
This makes no sense at all. You have a 2 dimensional matrix. But you define
y(i) = 2 * y(i-1) * (1-y(i-1))
So a function of only ONE index.
Respuestas (2)
William Rose
el 8 de Sept. de 2021
I see from your comment that you want the transpose. Therefore do this:
y=zeros(1,20);
y(1)=0.4;
for i=2:20, y(i)=2*y(i-1)*(1-y(i-1)); end
y=reshape(y,[4,5])';
disp(y)
Try.
1 comentario
aziz monavar
el 8 de Sept. de 2021
Editada: aziz monavar
el 9 de Sept. de 2021
William Rose
el 8 de Sept. de 2021
You have a matrix y(i,j) but your formula is only for y(i). That is the problem @John D'Errico identifies.
If you want to treat your 4x5 matrix as if it were 1x20, you can apply your formula, and then reshape the vector to a 4x5 matrix. The code to do it is
y=zeros(1,20);
y(1)=0.4;
for i=2:20
y(i)=2*y(i-1)*(1-y(i-1));
end
y=reshape(y,[4,5]);
disp(y)
Try it.
1 comentario
Ver también
Categorías
Más información sobre Assembly 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!