Info
This question is closed. Reopen it to edit or answer.
IF statement inside a FOR loop ERROR
7 views (last 30 days)
Show older comments
Using h as the FOR loop index variable, begin h at a value of 7,000,000 meters and decreasing h in steps of 0.01 meters, to 4,750,000 meters.
Use the IF statement to detect the first instance when the value of g is within 0.000001 m/s2of 2.53 m/s2. This will be the IF statement’s test. When g and go are that close, then you have found 'h'.
clear; clc; re=6371000; go=9.81; h=700000; x=0; n=1; w=1;
for m =1:n for q=1:w
g=go*((re/(re+h))^2);
if (abs(2.53 - g) < 1e-6)
x=h;
else
w=w+1;
h=h-0.01;
end
end
end
x
0 Comments
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!