ODE45 projectile angle input
이전 댓글 표시
Hi! Im trying (like many others have done previously) to plot the course of a projectile with ODE45.
After reading quite a few different examples, I still cant figure out how to intergrate an angle at which my projectile will be launched at, in my code.
Please would someone give an example of how to do it with my code, and an explination because Im struggling a lot even after having read lots!
Much appreciated!!
clf,clear,clc;
initial_conditions = [0, 40.96, 0, 28.68]'; %order of variables. (x start displacement = 0, x komponent initial speed = 40.96, y start displacement=0, y component initial speed = 28.68)
tspan = [0,7];
[t,Y] = ode45(@fun1, tspan, initial_conditions);
subplot(2,1,1)
plot(Y(:,1), Y(:,3)) %plotting x dispacement (1st var) with y displacement (3rd var)
ylim([0 50])
[t,Y] = ode45(@fun2, tspan, initial_conditions);
subplot(2,1,2)
plot(Y(:,1), Y(:,3)) %plotting x dispacement (1st var) with y displacement (3rd var)
ylim([0 50])
hold on
f = @(p) p;
x = linspace(0,250);
plot(x, f(x))
grid on
title('txt')
xlabel('xlabel')
legend('path','jhg')
function dX = fun1(t, X) %X is initial conditions, then stepped
g = 9.81;
dX = zeros(4,1);
dX(1) = X(2); %dx/dt = vx
dX(2) = 0; %dx^2/dt^2 = 0
dX(3) = X(4); %dy/dt = vy
dX(4) = -g; %dy^2/dt^2 = -g
end
function dX = fun2(t, X)
g = 9.81;
drag = 0.0;
dX = zeros(4,1);
dX(1) = X(2); %dx/dt = vx
dX(2) = -drag*X(2); %dx^2/dt^2 = 0
dX(3) = X(4); %dy/dt = vy
dX(4) = -g-drag*X(4); %dy^2/dt^2 = -g
end
댓글 수: 2
Sam Chak
2022년 5월 12일
@Emmanuelle Harper, What exactly do you mean by the following?
drag = 0.0;
Emmanuelle Harper
2022년 5월 12일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!