- 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?
FOR LOOP , beginner question.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hamada Alkhlif
am 15 Apr. 2021
Bearbeitet: Jan
am 15 Apr. 2021
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
Akzeptierte Antwort
Daniel Pollard
am 15 Apr. 2021
Bearbeitet: Daniel Pollard
am 15 Apr. 2021
Your code is
d = [];
for x=[0.1000,0.1500,0.2000]
d=[d ((34.63/x)-5.126)/2.54];
disp ("ANSWER");
end
x=[0.1000 0.1500 0.2000];
fprintf("\t%4g\t\t%4g\n",[x;d])
If I understand right, you want
d = [];
x=[0.1000,0.1500,0.2000];
for xi = 1:numel(x)
d=[d ((34.63/x(xi))-5.126)/2.54];
disp ("ANSWER");
fprintf("\t%5.4f\t\t%.4f\n", [x(xi);d(xi)])
end
7 Kommentare
Weitere Antworten (1)
Jan
am 15 Apr. 2021
Bearbeitet: Jan
am 15 Apr. 2021
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].')
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!