How do I nicely represent the final answer?
이전 댓글 표시
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)
댓글 수: 8
Bob Thompson
2019년 10월 28일
What do you mean by 'nicely represent?' This seems like an asthetic question, which is very arbitrary, in my opinion.
The Merchant
2019년 10월 28일
Bob Thompson
2019년 10월 28일
편집: Bob Thompson
2019년 10월 28일
That didn't really answer my question. What is wrong with having lambda just output as a variable? Do you want it output in a file? Do you want it displayed in a text message? Do you want to plot the values? Do you want to make a GUI for it? Do you want to post it to a website?
The Merchant
2019년 10월 28일
Bob Thompson
2019년 10월 28일
The Merchant
2019년 10월 28일
Bob Thompson
2019년 10월 28일
Make a variable for it. I can't really do that for you because I don't really know what lambda represents for your code. I assume it's an angle, because you have theta and are using cos and sin, but that's about all I know.
Adam Danz
2019년 12월 15일
Original question by OP in case it is deleted (this user has deleted many questions after being answered).
------------------------------------------------------------------
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개)
카테고리
도움말 센터 및 File Exchange에서 Aerospace Blockset에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!