Skip to content
School of Physics
Home Our Teaching Resources C programming exd.html
Back to top

PHY3134 Exercise 4

This is an assessed exercise and should be handed in next week for quick feedback. It will be returned the following week.

Objectives

  1. To program a simple physics problem.
  2. To pratice writing functions and passing pointers to them.

Task

Vector product

  1. Revise the definition of the vector cross product in three dimensions. Given two vectors of length three you should have the formula to calculate their cross-product.
  2. Write a function that takes three vectors as its arguments and sets one to the cross-product of the other two.
  3. Call it from main() and do a few simple tests by hand. Keep a copy of this.

Angular momentum

  1. Revise the vector definition of angular momentum in terms of the cross-product of position and momentum.
  2. Define a structure to store the mass, position, velocity and angular momentum of a particle.
  3. Modify your cross-product function to take a pointer to a stucture as its argument and to calculate and store the particle's angular momentum. Call it from main().
  4. Now progress the particle forward in time (i.e. velocity is unchanged but position has changed by dt * velocity. Recalculate the angular momentum. Has it changed? Does this surprise you?

Hand in both programs and some representative output.

When things go wrong

If you've gone 15 minutes without making progress (outside of lab time) ask me for help, either in person or by email. Always show me the complete, latest code.
                                                                                                                                                                                                                                                                       

Validate   Link-check © Copyright & disclaimer Share
Back to top