Is there anybody who can help me solve with this problem? Please help me~
조회 수: 11 (최근 30일)
이전 댓글 표시
- The motion of a projectile fired from a cannon at an angle with initial velocity is given by
y=y0+v0*sind(theta)*t-(g*t^2)/2
x=x0+v0*cosd(theta)*t
Given g=9.8 m/s/s, y0 =1 m/s, v0=100 m/s^2, produce 5 plots for angles [15:15:85] degrees. The vertical access should indicate the y value, and the horizontal access should indicate the x value for each point. Each plot should stop once the y value is less than zero. Use different symbols for each plot. Include a legend and axis labels.
댓글 수: 3
Steven Lord
2019년 1월 21일
Okay. I ran the code and found three minor problems.
- Don't use "smart quotes" in your code. If you're writing code in Microsoft Word I recommend using the MATLAB Editor instead.
- You misspelled xlable (it should be xlabel) and ylable (use ylabel).
- I strongly recommend ending your lines wih semicolons to suppress the output, particularly when you're working with longer vectors or larger matrices.
If none of those are the problem that you need help solving with this code, please tell us the details of that problem. What does the code do that you don't want it to do? Or is it not doing something you want it to do?
채택된 답변
Image Analyst
2019년 1월 21일
If you delete the if y<0 line, and fix the quotes and function names, it seems to work:
g = 9.8;
y0 = 1;
x0 = 0;
v0 = 100;
a = [15:15:85]
length_a = length(a)
t = [0:0.01:500];
k = 1
while k <= length_a
thisAngle = a(k);
y = y0 + v0*sind(thisAngle)*t - (g*t.^2)/2;
x = x0 + v0*cosd(thisAngle)*t;
plot(x,y, '-', 'LineWidth', 2)
grid on;
hold on;
legends{k} = sprintf('%d', thisAngle);
k = k+1
end
grid on;
title('plot of y vs x')
xlabel('Values of x')
ylabel('Values of y')
legend(legends);
추가 답변 (1개)
Image Analyst
2019년 1월 21일
For what it's worth, I attach (again) my projectile demo. It has just about every possible input and computes about every possible output you can think of. Extract the relevant parts you need. It's very well commented.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!