I know this is a programming language question, but no one seems to answer in that Forum. I'm running a program in Matlab and I'm running two loops One for the velocities in the x,y,z components and another for the magnus force (spin) vx,vy,vz. I'm holding all constant except vy and vz which I switch one at a time while holding the other constant. I need to find the spin in the vy then the vz that makes it within my constraints I have in place in my program. I try running now but it is just non-stop numbers that come out any help will be great. Thank you(adsbygoogle = window.adsbygoogle || []).push({});

clear;

Cd = .5;

Cs = .5;

p = 1.2; %Air density

r = .11303; %radius

m = .4536; %mass

x(1) = 0; %initial position

y(1) = 0;

z(1) = 0;

wx = 0; %initial angular velocity for x

wy = 0;

vx(1) = 14.95; %intial velocity for x

vy(1) = 14.5;

vz(1) = 7.9;

k = -300;

g = 9.81; %gravity

dt = .001;

t = 20;

n = t/dt;

for j = 1:n

wz = j;

for i = 1:n

u = sqrt((vx(i))^2+(vy(i))^2+(vz(i))^2); %v for all components

ax = (-((Cd*p*pi*r^2)*u*vx(i))/(2*m) - ((Cs*p*pi*r^3*(vz(i)*wy-wz*vy(i)))/(2*m)));

ay = (-((Cd*p*pi*r^2)*u*vy(i))/(2*m) - ((Cs*p*pi*r^3*(wz*vx(i)))/(2*m)));

az = ((-g)-((Cd*p*pi*r^2)*u*vz(i))/(2*m) + ((Cs*p*pi*r^3*(-wy*vx(i)))/(2*m)));

Fx = ax*m; %Force for x-component

Fy = ay*m;

Fz = az*m;

vx(i+1) = vx(i) + ((Fx/m)*dt); %Final velocity for x-component

vy(i+1) = vy(i) + ((Fy/m)*dt);

vz(i+1) = vz(i) + ((Fz/m)*dt);

x(i+1) = x(i) + vx(i+1)*dt;

y(i+1) = y(i) + vy(i+1)*dt;

z(i+1) = z(i) + vz(i+1)*dt;

if(x(i+1)>(11.531+ .1524))

break

end

if((y(i+1)>10.9564)&(y(i+1)<11.531))&((z(i+1)>1.8288)&(z(i+1)<2.3254))&((x(i+1)>11.531)&(x(i+1)<(11.531+.1524)))

fprintf('q')

break

end

end

fprintf('number %g',wz);

end

plot3(x,y,z)

grid on

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab Kinematics question

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**