2 views (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)

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Direct link to this comment

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

⋮## Direct link to this comment

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

## Direct link to this comment

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

⋮## Direct link to this comment

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

## Direct link to this comment

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

⋮## Direct link to this comment

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

Sign in to comment.