1 view (last 30 days)

My code:

v0 = 10

gamma = 0.1

for k=1:101

theta = 0.8444 * pi/4 + (k-51)*0.0001;

dt = 0.0000001;

x = 0;

y = 0;

vx = v0 * cos(theta);

vy = v0 * sin(theta);

x = x + dt * vx;

y = y + dt * vy;

while (y>0)

v = sqrt(vx*vx+vy*vy);

vx = vx - dt * gamma * vx;

vy = vy - dt * 9.81 - dt * gamma * vx;

x = x + dt * vx;

y = y + dt * vy;

end;

t(k) = theta

a(k) = x

end;

plot(a)

[vv, jv] = max(a)

t(jv) / (pi/4)

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 3 Comments

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/487808-how-do-i-properly-nicely-comment-this-code#comment_760738

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/487808-how-do-i-properly-nicely-comment-this-code#comment_760738

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/487808-how-do-i-properly-nicely-comment-this-code#comment_760739

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/487808-how-do-i-properly-nicely-comment-this-code#comment_760739

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/487808-how-do-i-properly-nicely-comment-this-code#comment_778138

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/487808-how-do-i-properly-nicely-comment-this-code#comment_778138

Sign in to comment.