How do I nicely present the final result of my code, so that it nicely fits the problem.
2 views (last 30 days)
Show older comments
Problem: On a flat field a canon ball with mass m is fired under an angle θ with an initial velocity of v0. Example 1.8 showed that the horizontal distance is R = v0^2 / g * sin 2θ. So the optimal angle is equal to π/4: then R = v0^2 /g. Solve the same problem in case m = 1 kg, v0 = 10 m/s, g = 9.81 m/s^2, but now including a friction force equal to: Ð→ F w = −γ∣ Ð→v ∣ Ð→v = −γvÐ→v , γ = 0.1. Find λ in θ = λπ/4 for which the distance is maximal. For every correct digit in the value of λ you score 0.1 point with a maximum of 0.5 in total. The value of λ starts with 0, for you to find p1, p2, p3, p4, p5 in λ = 0.p1p2p3p4p5, with every 0 ≤ pk ≤ 9.
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)
0 Comments
Answers (0)
See Also
Categories
Find more on Gamma Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!