finding intercept point in the plot
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
close all
theta = 50;
v0=200;
slope= 0.1;
vx=v0*cosd(theta); %horizontal component of velocity vector
vy=v0*sind(theta); %vertical component of velocity vector
g=9.807;
tf=2*vy/g; %total flight time
t=linspace(0,tf,150);
for r=1:length(t)
x(r)=vx*t(r); %horizontal postion
A(r)=vy*t(r)-0.5*g*t(r)^2; %vertical postion of particle
R(r)=x(r)*slope; %vertical postion of terrain
end
figure(1)
plot(x,A,'b')
hold on
plot(x,R,'m')
title('Altitude VS Range')
xlabel('Range')
ylabel('Altitude')
legend({'Range','Line of Terrain'},'Location','southwest')
grid on
hold on
채택된 답변
Star Strider
2021년 4월 8일
Try this:
theta = 50;
v0=200;
slope= 0.1;
vx=v0*cosd(theta); %horizontal component of velocity vector
vy=v0*sind(theta); %vertical component of velocity vector
g=9.807;
tf=2*vy/g; %total flight time
t=linspace(0,tf,150);
for r=1:length(t)
x(r)=vx*t(r); %horizontal postion
A(r)=vy*t(r)-0.5*g*t(r)^2; %vertical postion of particle
R(r)=x(r)*slope; %vertical postion of terrain
end
[Amax,idx] = max(A);
x_int = interp1(A(idx:end)-R(idx:end), x(idx:end), 0);
y_int = interp1(x, R, x_int);
figure(1)
plot(x,A,'b')
hold on
plot(x,R,'m')
plot(x_int, y_int, 'rs')
title('Altitude VS Range')
xlabel('Range')
ylabel('Altitude')
legend({'Range','Line of Terrain','Intercept'},'Location','southwest')
grid on
hold off
.
댓글 수: 16
thank you. do you know how to added so it shows the actual x and y intercept coordinates in the plot?
As always, my pleasure!
Yes! Add this line after the hold off call:
text(x_int, y_int, sprintf('$(%.1f, %.1f)\\rightarrow$',x_int,y_int), 'Horiz','right', 'Vert','middle', 'Interpreter','latex')
thank you
As always, my pleasure!
I decided to create a function out of part of the previous code:
function distance = ballistics(theta)
v0=200;
slope= 0.1;
vx=v0*cosd(theta); %horizontal component of velocity vector
vy=v0*sind(theta); %vertical component of velocity vector
g=9.807;
tf=2*vy/g; %total flight time
t=linspace(0,tf,150);
for r=1:length(t)
x(r)=vx*t(r); %horizontal postion
A(r)=vy*t(r)-0.5*g*t(r)^2; %vertical postion of particle
R(r)=x(r)*slope; %vertical postion of terrain
end
[Amax,idx] = max(A);
x_int = interp1(A(idx:end)-R(idx:end), x(idx:end), 0);
y_int = interp1(x, R, x_int);
distance = -hypot(x_int,y_int);
end
theta_est = fminunc(@ballistics, 60)
producing:
theta_est =
47.8559
Note that it returns the negative of the hypotenuse (by design), so the minimum value of the ‘ballistics’ function will be the maximum range angle.
i not sure how to use the fminunc function to ge the theta_est
Star Strider
2021년 4월 13일
Just use the code I posted.
It will likely be necessary to save the ‘ballistics’ function somewhere on your MATLAB search path first.
its not comming out with the theta est
Star Strider
2021년 4월 13일
The code I posted ran for me without error. I have no idea what the problem could be.
so i just copy the new code and put it at the bottom of the first code
Star Strider
2021년 4월 13일
If you have R2016b or later (if I remember correctly that was when functions were first allowed at the end of scripts), open a new script and put the ‘ballistics’ function at the end of it. Then run the fminunc call from above it. (I first ran it in a function I use for such purposes, then later saved it as a separate file to be certain that worked, and did the fminunc call each time. Both worked.)
sorry i just dont know how to do all that
Download the attached file to a directory in your MATLAB search path.
Then from the Command Window or a script, run it by running:
ballistics_fminunc_demo
or if you have it open in a tab in your Editor window, and you can do that with:
edit('ballistics_fminunc_demo.m')
click on the green Run arrow. The result will appear in your Command Window.
got it thank you
Star Strider
2021년 4월 13일
s always, my pleasure!
추가 답변 (2개)
FRANCISCO CORTEZ
2021년 4월 12일
0 개 추천
How can i determine the initial angle of the projectile with respect to the horizontal in order to achieve maximum range
Image Analyst
2022년 5월 22일
0 개 추천
See attached demo that computes just about everything you could ever want to know about a projectile.
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
제품
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)

