How to Find the Spin in vy and vz in Matlab?

In summary: Your Name]In summary, the forum member is having trouble with the output of their program in Matlab. They are trying to simulate the motion of an object and find the spin in the vy and vz components that will meet certain constraints. Suggestions are given to break down the problem into smaller parts, plot the output, and debug the code.
  • #1
starbaj12
49
0
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

Matlab:
clear;
Cd = .5;
Cs = .5;
p = 1.2; %Air density
r = .11303; %radius
m = .4536; %massx(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
 
Last edited by a moderator:
Physics news on Phys.org
  • #2

I understand that you are running a program in Matlab and are having trouble with the output. From the code you have provided, it seems that you are trying to simulate the motion of an object through the air and are trying to find the spin in the vy and vz components that will meet certain constraints.

I suggest breaking down your problem into smaller parts and testing each component separately. For example, you can first test the effect of changing the spin in only the vy component while keeping all other variables constant. Once you have determined the effect of this change, you can then move on to testing the vz component.

Additionally, it may be helpful to plot the output of your program to better visualize the motion of the object and see if it matches your expectations. You can also try debugging your code by adding print statements throughout the loops to see how the variables are changing.

I hope this helps and wish you success in your programming endeavors.
 
  • #3


Thank you for your question. It seems like you are trying to find the spin values for vy and vz that will satisfy your constraints in the program. One way to approach this problem is to use a nested for loop where you vary the values of vy and vz within a certain range and then check if the constraints are satisfied. If they are, then you can store those values and break out of the loop. Here is an example code:

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;

% define range for vy and vz values
vy_range = 14:0.1:15;
vz_range = 7:0.1:8;

% initialize variables to store spin values that satisfy constraints
spin_vy = 0;
spin_vz = 0;

for vy_val = vy_range
for vz_val = vz_range
% reset variables for each loop iteration
x(1) = 0; %initial position
y(1) = 0;
z(1) = 0;

vx(1) = 14.95; %intial velocity for x
vy(1) = vy_val;
vz(1) = vz_val;

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
 

1. What is Matlab Kinematics?

Matlab Kinematics is a computational tool used in the field of physics and engineering to analyze and simulate the motion of objects in space. It allows for the calculation of position, velocity, and acceleration of objects based on their initial conditions and any applied forces or constraints.

2. How is Matlab Kinematics used in research and industry?

Matlab Kinematics is commonly used in research and industry for tasks such as designing and optimizing robotic systems, analyzing the motion of mechanical components, and modeling the behavior of complex systems. It can also be used for simulation and control of dynamic systems in fields like aerospace, automotive, and biomechanics.

3. What are some key features of Matlab Kinematics?

Some key features of Matlab Kinematics include the ability to create 2D and 3D models, perform inverse and forward kinematics calculations, and visualize motion through animations and graphs. It also has a user-friendly interface and a wide range of built-in functions and toolboxes for various applications.

4. Is Matlab Kinematics difficult to learn?

Like any programming language, Matlab Kinematics can be challenging to learn at first. However, with practice and dedication, it can become a powerful tool for analyzing and simulating motion. There are also many online resources and tutorials available to help with the learning process.

5. Can Matlab Kinematics be used for real-time applications?

Yes, Matlab Kinematics can be used for real-time applications by integrating it with other software or hardware systems. It also has the capability to generate code for embedded systems, making it suitable for real-time control and monitoring of physical systems.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
569
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
997
  • Special and General Relativity
Replies
11
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
Back
Top