FOR LOOP , beginner question.
Mostra commenti meno recenti
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 Commenti
Daniel Pollard
il 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
il 15 Apr 2021
Try
fprintf("\t%8.4f\t%8.4f\n",[x;d])
using %g strips insignificant trailing zeros
Risposta accettata
Più risposte (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 Commento
Hamada Alkhlif
il 15 Apr 2021
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
