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!