FOR LOOP , beginner question.
Mostrar comentarios más antiguos
i want to Write a code or script including a FOR LOOP in order to computing the value of d for the following values of x and returning an output variable named ANSWER just as shown : x = 0.10, x = 0.15, and x = 0.20

3 comentarios
Daniel Pollard
el 15 de Abr. de 2021
Can you give more detail, such us -
- Where do these numbers come from? How were they found in the first place?
- What have you tried so far?
- What sort of calculation do you expect to be inside the for loop?
Hamada Alkhlif
el 15 de Abr. de 2021
Try
fprintf("\t%8.4f\t%8.4f\n",[x;d])
using %g strips insignificant trailing zeros
Respuesta aceptada
Más respuestas (1)
disp ("ANSWER");
for x = [0.10, 0.15, 0.20]
d = ((34.63 / x) - 5.126) / 2.54;
fprintf("%12g%12g\n", x, d)
end
Or:
x = [0.10, 0.15, 0.20]
d = ((34.63 ./ x) - 5.126) / 2.54; % .7 for elementwise division
fprintf('Answer:\n');
fprintf("%12g%12g\n", [x, d].')
1 comentario
Hamada Alkhlif
el 15 de Abr. de 2021
Categorías
Más información sobre Logical 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!
