FOR LOOP , beginner question.
显示 更早的评论
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 个评论
Daniel Pollard
2021-4-15
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
2021-4-15
Try
fprintf("\t%8.4f\t%8.4f\n",[x;d])
using %g strips insignificant trailing zeros
采纳的回答
更多回答(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].')
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
