x0=0;y0=5;v0=10;theta = 35;g = 9.81; % Gravitational constant
vx0 = v0*cosd(theta); % Inital velocity in the x direction
vy0 = v0*sind(theta); % Inital velocity in the y direction
T = 2*vy0/g ; % Time in flight (y0 = 0)
Hmax = ((v0^2*(sin(theta))^2)/(2*g) + y0); % Maximun height of projectile
VLength = 1000;x = zeros(VLength,1);x(1) = x0;y = zeros(VLength,1);y(1) = y0;t = zeros(VLength,1);t(1) = 0.02;for k = 2:VLength; % Starts the for loop
x(k) = v0*t*cosd(theta) + x0; % Calculating x direction
y(k) = v0*t*sind(theta) - 1/2*g*t^2 +y0; % Calculating y direction
t(k) = 0.2*(k-1); if y < 0 break endend
MATLAB: I’m having difficulty getting this code to work, could someone explain how to fix this “In an assignment A(I) = B, the number of elements in B and I must be the same. ” error
a(i) = bMATLABnumber of elements
Related Question
- How to implement the following
- How to create a vector with for loop
- Projectile motion with drag and magnus effect. So far im just trying to make it work with air resistance however I get a Index exceeds the number of array elements (1). Error in projectile_golf (line 36) vx(i)=vx(i-1)-FdragX(i-1)*dt;
Best Answer