I must find the magnitude of the h step in order to have an x_impact accuracy of 0.1m. I dont understand why when I change my dt my final impact distance changes so drastically when its supposed to approach a final more accurate result.
조회 수: 1 (최근 30일)
이전 댓글 표시
function Projectile_motion_variation_drag_Magnus
clear
clc
format long g;
workspace
format compact
fontSize = 20;
g = 10; % acceleration due to gravity in Y
y0 = 0; % intial position y
vHit = 50; % initial velocity magnitude
wHit = 100; % Angular Velocity (rad/s)
Angle = 30; % angle of strike
Variation = 0;
if Variation == 1
v0Max = vHit/10 + vHit;
v0Min = vHit - vHit/10;
v0 = randi([v0Min v0Max],1) %randomly generated v0
wMin = wHit - wHit/10;
wMax = wHit + wHit/10;
Angular_w = randi([wMin wMax],1) % randomly generate w
aMin = Angle - Angle/10;
aMax = Angle + Angle/10;
Alpha = randi([aMin aMax],1) % Angle Alpha hit
else
v0 = vHit
Angular_w = wHit
Alpha = Angle
end
c = 4.5*10^(-5); % Coefficient of drag
r = 21.5*10^(-3); % Radius of gold ball
m = 46*10^(-3); % Mass of golf ball
rho_air = 1.2; % Density of air
p = [0 0 0];
dt=0.1;
t=[0:dt:200];
v = v0; % Velocity Magnitude
Velx = v(1)*cosd(Alpha);
Vely = v(1)*sind(Alpha)- g*t(1);
Vel(1,:) = [Velx Vely 0] ; % Velocity Vector
FdragX(1) = v(1).*Vel(1).*c; % Drag force in X direction
FdragY(1) = v(1).*Vel(2).*c; % Drag force in Y direction
AccDragX(1) = -FdragX(1)./ m; % F=M*A decceleration due to drag in X
AccDragY(1) = -FdragY(1)./ m; % F=M*A decceleration due to drag in Y
AccDrag(1,:) = [AccDragX(1) AccDragY(1) 0]
u = (pi^2 * rho_air * r^3 * Angular_w); % Formula for U in z axis
uForce = [0 0 u] % Magnus force in Z
Magnus(1,:) = cross(uForce,Vel(1,:)) % Cross Product of M_force
AccMagnus(1,:) = Magnus(1,:)./m
for i=2:length(t)
p(i,:) = p(i-1,:) + Vel.*dt + AccDrag.*(dt.^2) + AccMagnus.*(dt.^2);
Vel = Vel + AccDrag.*dt + AccMagnus.*dt;
v= sqrt(sum((Vel.^2),"all"));
Velx = v*cosd(Alpha);
Vely = v*sind(Alpha)- g.*t(i);
Vel = [Velx Vely 0]
FdragX = v.*Velx*c; % Drag force in X direction
FdragY = v.*Vely*c; % Drag force in Y direction
AccDragX = -FdragX./ m; % F=M*A decceleration due to drag in X
AccDragY = -FdragY./ m; % F=M*A decceleration due to drag in Y
AccDrag = [AccDragX AccDragY 0];
Magnus = cross(uForce,Vel); % Cross Product of M_force
AccMagnus = Magnus./m; %Acceleration due to magnus force
if p(i,2)<0
break
end
end
fprintf('Velocity with variation' ,v0, 'm/s')
xImpact_no_Drag = (sind(2*Alpha)*(v0^2))/g
p(end,:)
v0
Angular_w
Alpha
댓글 수: 1
John D'Errico
2020년 12월 25일
Before you do anything, have you verified that the code is working properly, to predict a reasonable projectile motion? Spend some time to look at that. You are modleing what, a golf ball? Is it predicting anything reasonable? What does the flight do?
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!