How do I contain this in one "for" loop?
Mostrar comentarios más antiguos
fprintf('Problem 2: \n')
for index = 1:1:1
n_value=input('Please, input an n value: \n');
n=1:1:5;
manipulate_n=1./(2.^n);
sum1=sum(manipulate_n);
fprintf('There are %f n values, the sum is %f, and the difference is %f \n',length(n),sum1,1-sum1)
end
for index = 1:1:1
n_value2=input('Please, input an n value: \n');
n2=1:1:10;
manipulate_n2=1./(2.^n2);
sum2=sum(manipulate_n2);
fprintf('There are %f n values, the sum is %f, and the difference is %f \n',length(n2),sum2,1-sum2)
end
for index = 1:1:1
n_value3=input('Please, input an n value: \n');
n3=1:1:40;
manipulate_n3=1./(2.^n3);
sum3=sum(manipulate_n3);
fprintf('There are %f n values, the sum is %f, and the difference is %f \n',length(n3),sum3,1-sum3)
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!