Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numerical Approximation1  You have some Physics equation or equations which need to be solved  But: You can’t or don’t want to do all that mathematics,

Similar presentations


Presentation on theme: "Numerical Approximation1  You have some Physics equation or equations which need to be solved  But: You can’t or don’t want to do all that mathematics,"— Presentation transcript:

1 Numerical Approximation1  You have some Physics equation or equations which need to be solved  But: You can’t or don’t want to do all that mathematics, or The equations can not be solved What to do? Numerical Approximation

2 2 Numerical Approximation Module  Based on the Python programming language and the Visual Python package VPython  We will investigate a system that you will soon be exploring in some detail in the course: the oscillating spring-mass system

3 Numerical Approximation3 About Python and VPython  An ideal 1 st programming language  Not a toy: used for production programs by Google, YouTube, etc.  Open source  Traditionally for all languages, for beginners the first “program” only prints: hello, world

4 Numerical Approximation4 Here is a complete Python program that prints: hello, world print ”hello, world” Note the quotes Totally intolerant of typing mistakes: this will not work prind ”hello, world” Case sensitive: this won’t work either Print ”hello, world”

5 Numerical Approximation5 The VPython environment To run the program, click on Run and choose Run Module Here is a VPython window ready to run our first program

6 Numerical Approximation6 A second window will appear:

7 Numerical Approximation7 Another complete Python program that prints hello, world what = ”world” print ”hello,”, what First Python executes the first line of the program A variable named what is given the value world Next Python executes the second line of the program: it prints hello, followed by the value of the variable what

8 Numerical Approximation8 Loops Often we wish to have a program execute the same lines over and over Loops do this Example: x = 0 while x < 3: print x x = x + 1 Assign variable x a value of 0 Is x less than 3? If so, execute the following lines of program. If not, stop Increase the value of x by 1. Go back to the while statement

9 Numerical Approximation9 The Spring-Mass System The force exerted on the mass by the spring: F = -k x (Hooke’s Law) F = m a (Newton’s Second Law) Combine to form a differential equation:

10 Numerical Approximation10 Solving Differential Equations 1. Learn the math, or 2. Find a mathematician, or 3. Get hold of software that can solve differential equations, such as Maple or Mathematica If you choose #2, note that you don’t need to tell them what, if anything, the equation is about Solving differential equations has nothing to do with Physics!

11 Numerical Approximation11 The Mathematical Solution You will be learning about this soon in class

12 Numerical Approximation12 Avoiding all that mathematics 1.Calculate the acceleration a = - (k/m) x 2.Calculate its speed a small time  t later: v new = v + a  t 3.Calculate its position a small time  t later: x new = x + v new  t Recall: ma = -kx At some time t we know the position x of the mass and its speed v Go back to #1 and repeat over and over

13 Numerical Approximation13 Avoiding all that mathematics continued 1.Calculate the acceleration a = - (k/m) x 2.Calculate its speed a small time  t later: v new = v + a  t 3.Calculate its position a small time  t later: x new = x + v new  t Go back to #1 and repeat over and over. This can be made as close to correct as we desire by making the “time step”  t sufficiently small This method is “numerical approximation”

14 Numerical Approximation14 What you will do today  We have prepared a VPython program that animates the mass of a spring-mass system two different ways: 1.By coding the solution to the differential equation 2.By numerical approximation You will examine the code and identify which parts do what


Download ppt "Numerical Approximation1  You have some Physics equation or equations which need to be solved  But: You can’t or don’t want to do all that mathematics,"

Similar presentations


Ads by Google