Professional Documents
Culture Documents
Numer Approx
Numer Approx
You have some Physics equation or equations which need to be solved But: You cant or dont want to do all that mathematics, or The equations can not be solved
Numerical Approximation
Numerical Approximation
Here is a VPython window ready to run our first program To run the program, click on Run and choose Run Module
Numerical Approximation 5
Numerical Approximation
Loops
Often we wish to have a program execute the same lines over and over Loops do this Assign variable x a value of 0 Example: Is x less than 3? If so, execute the x = 0 following lines of while x < 3: program. If not, stop print x Increase the value of x = x + 1 x by 1. Go back to the while statement
Numerical Approximation 8
The force exerted on the mass by the spring: F = -k x (Hookes Law) F=ma (Newtons Second Law) Combine to form a differential equation:
d x ma m 2 kx dt
Numerical Approximation 9
d x m 2 kx dt
3. Get hold of software that can solve differential equations, such as Maple or Mathematica If you choose #2, note that you dont need to tell them what, if anything, the equation is about Solving differential equations has nothing to do with Physics!
Numerical Approximation 10
x A sin(t )
d x m 2 kx dt
2
k m
Numerical Approximation
11
1. Calculate the acceleration a = - (k/m) x 2. Calculate its speed a small time Dt later: vnew = v + a Dt 3. Calculate its position a small time Dt later: xnew = x + vnew Dt Go back to #1 and repeat over and over
Numerical Approximation 12
This can be made as close to correct as we desire by making the time step Dt sufficiently small
Numerical Approximation
13
Numerical Approximation
14