How Does Spin Affect a Soccer Ball's Trajectory in Matlab Simulation?

In summary: I'm trying to model the motion of a soccer ball in air using numerical methods. The program takes into account air resistance (Cd and Cs) and the ball's initial velocity, position, and angular velocity. The goal is to find the values of spin (wz or wy) needed to score a goal in the upper right hand corner of the goal. The program is not giving me the desired output, so I may need to adjust the fprintf statement or the stopping condition. Suggestions for improvement could include using smaller time steps and simplifying the stopping condition. Additionally, the program could be optimized by avoiding unnecessary computations.
  • #1
em504346
1
0
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

This is a program that shows the force and spin it would take to put a soccer ball into the upper right hand corner of the goal. I found the values I wanted with no spin included. NOw I want to run the program and let it give me back the values of different spin it would take to get to this point of choice. I'm holding everything else constant including one or the other spin components wz or wy and just letting one of them very, wz or wy. I want the the program to tell me the values of spin, but IT IS NOT. Do I need to set the fprintf somewhere specific or what? Any suggestions would be great

THANKS
 
Last edited:
Physics news on Phys.org
  • #2
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);

Why to you multiply by m in one line then divide by it in the next? Why do unnecessary computations?

Try a smaller step. put a loop counter in, stop after a set number of time steps.

Are your numbers meaningful? It really seems like you have a complicated stopping condition, figure out something a bit simpler.
 
  • #3


The program looks well-written and it seems like you have a clear understanding of the variables and what they represent. It's not entirely clear what you are trying to achieve with the program, but here are some suggestions that may help you get the desired output:

1. Make sure you are running the program with the correct input values. In this case, it seems like you are trying to find the values of wz or wy that would result in the ball reaching the desired point in the goal. Therefore, you need to specify the initial values for wx and wy in the beginning of the program, and then use a for loop to iterate through different values of wz or wy.

2. Instead of using fprintf to print out the values of wz or wy, you can create an array to store the values and then plot them at the end of the program. For example, you can create an empty array before the for loop (e.g. spin_values = []) and then inside the for loop, use the command spin_values = [spin_values, wz] to add the values of wz to the array. Then, you can plot the array using the command plot(spin_values).

3. If you want to print out the values of wz or wy, you can use the fprintf command inside the for loop and specify which variable you want to print. For example, you can use fprintf('wz = %g\n', wz) to print out the value of wz for each iteration.

4. Double check your if statements to make sure they are checking for the correct conditions. It's not clear what the "q" and "number" outputs are supposed to represent, so make sure those are working as intended.

I hope these suggestions help you get the desired output from your program. Good luck!
 

Related to How Does Spin Affect a Soccer Ball's Trajectory in Matlab Simulation?

1. What is Matlab?

Matlab is a high-level programming language and interactive environment used for numerical computation, data analysis, and visualization. It is widely used in various fields such as engineering, mathematics, and science.

2. What is the "Look Matlab program inside" feature?

The "Look Matlab program inside" feature is a built-in function in Matlab that allows users to view the source code of any Matlab program or function. This is useful for understanding how a specific program works or for debugging purposes.

3. How do I use the "Look Matlab program inside" feature?

To use the "Look Matlab program inside" feature, simply type "type function_name" in the command window, where "function_name" is the name of the function or program you want to view. This will open the source code in the editor window.

4. Can I modify the source code using the "Look Matlab program inside" feature?

Yes, you can modify the source code using the "Look Matlab program inside" feature. However, it is recommended to make a copy of the original code before making any changes.

5. Is the "Look Matlab program inside" feature available for all functions and programs?

Yes, the "Look Matlab program inside" feature is available for all built-in and user-defined functions and programs in Matlab. However, some functions may not have source code available as they are compiled and protected by the creators.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
961
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top