Projectile motion with drag. Im not sure what Im doing wrong here but it tells me my matrix dimensions must agree however I thought that if I use .* it can multiply a scalar and a vector together

3 vues (au cours des 30 derniers jours)
function projectile_golf
clear
clc
format long g;
workspace
format compact
fontSize = 20;
g = 9.81; % acceleration due to gravity in Y
y0 = 0; % intial position y
v0 = 50; % initial velocity magnitude
Angular_w = 100; % Angular Velocity (rad/s)
angle = 30; % angle of strike
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
dt=0.1;
t=[0:dt:200];
v(1) = v0; % Velocity Magnitude
Vel = [v0*cosd(angle),v0*sind(angle)- g*t,0]; % Velocity Vector
FdragX(1) = v(1).*Vel(1).*c; % Drag force in X direction
FdragY(1) = v(1).*Vel(1).*c; % Drag force in Y direction
p = [0,0,0];
AccDrag = [FdragX(1)./ m, FdragY(1)./ m, 0]; % F=M*A decceleration due to drag
for i=2:length(t)
v(i) = sqrt((Vel(1)^2)+(Vel(2)^2));
p(i) = p(i-1) + Vel.*t - AccDrag.*(t^2);
v(i) = v(i-1);
Vel = [v(i)*cosd(angle),v(i)*sind(angle)- g*t,0];
FdragX(i) = v(i).*Vel(i).*c;
FdragY(i) = v(i).*Vel(i).*c;
AccDrag(i) = [FdragX(i)./m, FdragY(i)./m, 0];
end
plot(p)

Réponse acceptée

Image Analyst
Image Analyst le 20 Déc 2020
Perhaps you need to index all vectors by i
p(i) = p(i-1) + Vel.*t - AccDrag.*(t^2);
Vel and t are vectors, so try
p(i) = p(i-1) + Vel(i).*t(i) - AccDrag.*(t(i)^2);
AccDrag is a 3 element vector. I'm not sure which of the 3 values you want to use.

Plus de réponses (0)

Catégories

En savoir plus sur Physics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by