If you're not so happy with Python, and would rather use another language for calculating your rocket's motion, I've found a site with a much larger set of available languages for coding within the browser. If you already know, say, fortran or C++, this might be much easier - you can use what language you want and not have to worry about bringing a laptop.
Showing posts with label CODE. Show all posts
Showing posts with label CODE. Show all posts
Friday, February 28, 2014
Monday, February 17, 2014
Starting with Python
For tomorrow's "lab", we'll start messing around with python. Nothing fancy, just a few simple examples so you can learn to do basic calculations (like multiply stuff) and display the answer. We'll work our way up to more complicated things. If you are interested enough to mess around on your own, try the excellent tutorial here. Don't feel bad if you haven't programmed before. It will be weird at first, but you'll pick up enough to do what you need to in no time.
Sunday, February 16, 2014
Starting our project
As I mentioned on Friday, from now on we're going to stop with the usual labs and work on a project for the rest of the semester. The basic project is to characterize and simulate USB-controlled foam rocket launchers.
The ultimate goal will for you to be able to calculate numerically the flight of a realistic projectile and use this result to actually hit a target with the launcher. You will have to include drag forces and everything - using measured values of launch velocities, drag coefficients, etc. The experimental end of this will be measuring launch velocities, their variability, and trying to measure drag coefficients using the sensors we have. How to get a good measure of the drag coefficient will require some time and care. By the end, we should be able to specify a target, and you will perform the calculations and then actually hit the target.
The theoretical end of this is figuring out how to calculate things numerically. Projectile motion with drag can't be done analytically, so we'll need to learn how to simulate things. To start with, we can do this in pseudocode, as I did on Friday, just learning the appropriate algorithm for calculating trajectories numerically. Once you've got your head around how the process works, we can start with actual code. For those of you that can program, you're free to use any language you want and any methods you want. What you do has to make sense, and it has to work. For those of you that can't program, I'm going to teach you just enough Python to get the job done. We'll start learning basic python coding tomorrow; see the next post.
Friday, May 1, 2009
Reminder: code submission
Each team owes me code ... soon.
Don't worry about dependencies, libraries, etc. I'll figure it out.
Don't worry about dependencies, libraries, etc. I'll figure it out.
Thursday, April 16, 2009
Rocket launcher code
Linux kernel module to control the launchers. Should be portable ...
Update: code for OS X here. Pretty readable & hackable. You are not by any means required to include rocket launcher control in your code, this is just in case you're interested in trying it for 'fun.'
Update: code for OS X here. Pretty readable & hackable. You are not by any means required to include rocket launcher control in your code, this is just in case you're interested in trying it for 'fun.'
Thursday, April 9, 2009
Checking your code
In case you want to check that your code is working ...
If you use the drag equation
If you use the drag equation
F_d = \frac{1}{2}\rho C A \vec{v}\cdot\vec{v}
with starting parameters
v_x=31\,\text{m/s} \\
v_y=35\,\text{m/s}\\
m=0.046\,\text{kg}\\
A=0.00143\,\text{m}^2\\
\rho=1.225\,\text{kg}/\text{m}^3\\
C=0.25
then you should get a range of 126 meters over level ground (and 221 meters with C=0, i.e., no drag).
Wednesday, April 8, 2009
Research Work
If you like coding, and want to pick up some research work, let me know. Prof. Williams is in need of students to help out, particularly those who know some Java (though good coding skills are generally valuable, you can pick up the Java you need).
Cool factor: her experiment is a giant neutrino detector in Antarctica, see link above. (Pun intended.) Very exciting work, and you would have a chance to make a real contribution to a world-class international research project.
Let me know if you're interested, or contact Dr. Williams directly (via link above).
Cool factor: her experiment is a giant neutrino detector in Antarctica, see link above. (Pun intended.) Very exciting work, and you would have a chance to make a real contribution to a world-class international research project.
Let me know if you're interested, or contact Dr. Williams directly (via link above).
Tuesday, March 24, 2009
Coding for fun and profit
By the way: if you enjoy coding, I can probably find you an independent study in the department doing it for a real, live research project. Seriously - there are really not many students around who 1) enjoy coding, and 2) are any good at it. If you can answer yes to even one of those criteria, there is a job for you ...
In particular, the astronomers are always looking for someone, as are the condensed-matter theorists. The particle physicists also do a serious amount of numerical work, and could probably use your skills.
If you think you would be interested, let me know. You have the possibility of getting 400-level physics or astronomy credit during the semester, and actual cash during the summer. There is also no reason why it couldn't be a CBH project, that is not hard to arrange.
N.B. - Fortran is still in common use in physics, as are things like C/C++, python, etc.
In particular, the astronomers are always looking for someone, as are the condensed-matter theorists. The particle physicists also do a serious amount of numerical work, and could probably use your skills.
If you think you would be interested, let me know. You have the possibility of getting 400-level physics or astronomy credit during the semester, and actual cash during the summer. There is also no reason why it couldn't be a CBH project, that is not hard to arrange.
N.B. - Fortran is still in common use in physics, as are things like C/C++, python, etc.
Friday, March 6, 2009
Trajectory calculations
Here's a quick snippet of C code that illustrates the algorithm I was talking about today. Some key bits are missing, but it should give you an idea of what to do.
You start with the initial velocity and parameters, and from that calculate everything a time increment dt later. Repeat for many (many) such dt ...
If you don't read C, I can translate it to some other language upon request. If you request something odd like postscript or the like it may take longer ...
Note also that this only calculates the trajectory given some initial inputs. What you want is the launch angle that gives a certain range ... calculating the trajectory is only a portion of that problem.
You start with the initial velocity and parameters, and from that calculate everything a time increment dt later. Repeat for many (many) such dt ...
If you don't read C, I can translate it to some other language upon request. If you request something odd like postscript or the like it may take longer ...
Note also that this only calculates the trajectory given some initial inputs. What you want is the launch angle that gives a certain range ... calculating the trajectory is only a portion of that problem.
while (y>=0) {v = pow((vx*vx)+(vy*vy),0.5);}
theta = atan(vy/vx);
ax = ... ; // get these from your force equation
ay = ... ;
vx = vx + ax*dt;
vy = vy + ay*dt;
x = x + vx*dt+0.5*ax*dt*dt;
y = y + vy*dt+0.5*ay*dt*dt;
if (y<0)
y=0; // negative y means we hit the ground
// store various values here
t+=dt;
Sunday, February 22, 2009
HW 5 solutions
The solutions to Homework 5 are out.
Just for 'fun,' I included code snippets in various languages to solve the last problem, in which you needed to sum the harmonic series over 75 terms. Actually, I wrote quick versions in several languages, such was the depth of my procrastination. Represented are
(In particular, my postscript solution could be fancied up quite a bit for prettier output. The bash script is also a bit cheap and approximate, since one can only use integers.)
Just for 'fun,' I included code snippets in various languages to solve the last problem, in which you needed to sum the harmonic series over 75 terms. Actually, I wrote quick versions in several languages, such was the depth of my procrastination. Represented are
- C (iterative and recursive solutions)
- Pascal
- Perl
- LISP
- Python
- Java
- shell (bash) script
- Postscript
- Fortran
(In particular, my postscript solution could be fancied up quite a bit for prettier output. The bash script is also a bit cheap and approximate, since one can only use integers.)
Labels:
CODE,
homework,
solutions,
the-prof-is-daft,
utter_randomness
Monday, February 16, 2009
Homework 5, #7
By the way, here are a few code-based solutions that you submitted to homework 5 problem #7. Quite a variety - Fortran, C/C++, and Python are all represented.
My own (hastily-composed) version is here, in standard C. It should compile with vanilla gcc. It takes a command-line argument N, where N is how many terms of the harmonic series to evaluate. For "fun" I also included code (commented out) to calculate the same sum recursively.
For reference, here is the source of the problem (Car Talk), here is their answer, which employs the Euler–Mascheroni constant.
My own (hastily-composed) version is here, in standard C. It should compile with vanilla gcc. It takes a command-line argument N, where N is how many terms of the harmonic series to evaluate. For "fun" I also included code (commented out) to calculate the same sum recursively.
For reference, here is the source of the problem (Car Talk), here is their answer, which employs the Euler–Mascheroni constant.
Subscribe to:
Posts (Atom)