FOR LOOP , beginner question.
Show older comments
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 Comments
Daniel Pollard
on 15 Apr 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
on 15 Apr 2021
Try
fprintf("\t%8.4f\t%8.4f\n",[x;d])
using %g strips insignificant trailing zeros
Accepted Answer
More Answers (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 Comment
Hamada Alkhlif
on 15 Apr 2021
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!