For loop for equation
Mostrar comentarios más antiguos
Hi
I have a vector of 42*1 values and need to implement two other vectors(l and u) of the same size. The two vectors have a starting value of l(1)=0 and u(1)=1 but need to follow the equation as shown in the image.
My attempt at the code was
l=zeros(size(prob));
u=zeros(size(prob));
u(1,:)=1;
l(1,:)=0;
for i=2:length(u)
for j=2:length(l)
l(i)=l(i-1)+(u(j-1)-l(i-1))*prob(i-1);
u(j)=l(i-1)+(u(j-1)-l(i-1))*prob(j);
end
end
but this did not work. Any help is much appreciated
5 comentarios
Maaz Madha
el 15 de Dic. de 2021
Chris
el 15 de Dic. de 2021
If you post what you tried, we might be able to find something wrong with it.
Chris
el 15 de Dic. de 2021
Or, eventually someone will come along and answer your homework question for you.
Maaz Madha
el 15 de Dic. de 2021
Respuestas (1)
Voss
el 15 de Dic. de 2021
l=zeros(size(prob));
u=zeros(size(prob));
u(1,:)=1;
l(1,:)=0;
for i=2:length(u)
l(i)=l(i-1)+(u(i-1)-l(i-1))*prob(i-1);
u(i)=l(i-1)+(u(i-1)-l(i-1))*prob(i);
end
Categorías
Más información sobre Entering Commands en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

