ode45 projectile motion with drag in Y direction. help im desperate

조회 수: 9 (최근 30일)
Jacob Roach
Jacob Roach 2019년 3월 7일
답변: darova 2019년 3월 8일
tspan = [0:.001:3];
IC = [0,0];
[t,y] = ode45(@f,tspan,IC);
ydot = y(:,1);
ydub = y(:,2);
v0x = 10./sqrt(2);
x0 = 0;
y0 = 0;
x = x0 + v0x.*tspan + 0;
figure(1);hold on;axis on;
plot(x,y);
legend('ydot','ydub')
title('Projectile Motion')
xlabel('X-Position')
ylabel('Y-Position')
function ydub = f(t,y);
% [y] = [y(1), y(2)] = [y1, y2] = [ydot, ydub]
c = 0;
p = 0;
m = 1;
g = 9.8;
ydub = [y(2); (c.*(y(1).^p))./m - g];
end
I am trying to graph the position of a projectile with drag in the Y direction, but not in the X direction, in 2D on the x-y plane, using ODE45 to find the position equation. The equation of motion I obtained is Ydoubledot = (((C)*Ydot^p)/m) - g. My graph does not look right, I think it is supposed to go up then down. Attached are pics of the problem statement, and the graph I am getting. Help im dying. Thanks.
download1.png
download.png

답변 (1개)

darova
darova 2019년 3월 8일
function temp
tspan = 0:.001:1;
x0 = 0;
y0 = 0;
a = 45;
v0x = 10*cosd(a);
v0y = 10*sind(a);
u0 = [x0 y0 v0x v0y];
[t,y] = ode45(@f,tspan,u0);
X = y(:,1);
Y = y(:,2);
% vx = y(:,3);
% vy = y(:,4);
plot(X,Y)
axis equal
legend('Trajectory');
title('Projectile Motion')
xlabel('X-Position')
ylabel('Y-Position')
end
function ydot = f(t,u)
c = 0.5;
p = 2;
m = 1;
g = 9.8;
% u(1); % x
% u(2); % y
ydot(1,1) = u(3); % vx
ydot(2,1) = u(4); % vy
ydot(3,1) = -c/m*u(3).^p; % ax
ydot(4,1) = -c/m*u(4).^p -g; % ay
end

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by