Is there anybody who can help me solve with this problem? Please help me~

조회 수: 11 (최근 30일)
  1. 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
Jiangwen Cheng
Jiangwen Cheng 2019년 1월 21일
편집: Image Analyst 2019년 1월 21일
g=9.8;
y0=1;
x0=0;
v0=100;
a=[15:15:85];
k=length(a)
t=[0:0.01:500];
i=1
while i<=k
y=y0+v0*sind(a(i))*t-(g*t.^2)/2
x=x0+v0*cosd(a(i))*t
if y<0
end
plot(x,y)
i=i+1
end
title(plot of y vs x)
xlable(Values of x)
ylable(Values of y)
grid
This is what I finished.
Steven Lord
Steven Lord 2019년 1월 21일
Okay. I ran the code and found three minor problems.
  1. Don't use "smart quotes" in your code. If you're writing code in Microsoft Word I recommend using the MATLAB Editor instead.
  2. You misspelled xlable (it should be xlabel) and ylable (use ylabel).
  3. 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
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);
0000 Screenshot.png

추가 답변 (1개)

Image Analyst
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.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by