How to output the answer to a while loop into an array
31 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have the following code that is supposed to stop once h>1e-13, the problem that I am running into though is that the answer is supposed to be input into an array but I can't figure out how I am supposed to do that because I just keep getting an answer that is a single digit rather than an array with all of the values for h that where calculated this way.
h(1)=1;
hnew=h/2;
while hnew>=1e-13;
h=hnew;
hnew=h/2;
end
The code works like it is supposed to, but I just need to find out how to add each one of the iterations for h into an array
0 comentarios
Respuestas (1)
Voss
el 3 de Feb. de 2022
Maybe this is what you are going for:
h(1) = 1;
hnew = h/2;
while hnew >= 1e-13
h(end+1) = hnew;
hnew = h(end)/2;
end
disp(h);
disp(hnew);
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!