web stats stat24.com

Graphing Calculator at Work

Ordinary differential equations

Harmonic Oscillator

What Wikipedia says about oscillators:
A harmonic oscillator is either a mechanical system in which there exists a returning force F directly proportional to the displacement y, i.e. F = -A.y where A is positive and constant or any physical system that is analogous to this mechanical system, in which some other quantity behaves in the same way mathematically. Examples of harmonic oscillators include pendulums (in small angles), masses on springs, RLC circuits and acoustical systems.

Because force is defined as the product of second derivative of the position vector and mass, we may rewrite the equation above to the form

(if we don’t assume any damping force). Although this equation can be solved very easily analytically, you can use Small Math 2D’s ODE solver as well:

  1. Choose item “Differential equation” from menu “Plot”.
  2. Type the right side of the equation: -y. (Ignore the left side - it will automatically change, when we set the initial conditions).
  3. Set the initial conditions: The first condition stands for time x0 when we start our measurement, say at time zero. The second one is the position of the oscillator y0 in time x0, say y0 = 1. And the third condition stands for the velocity at time x0, we will assume an extreme at this position, so x(0)’=0.
  4. Press “Draw”.

Now, you should see something like this.

Oscillator

We could hardly ever see an oscillator like this in nature, because real oscillators are damped. However, describing such damping is quite complicated, so we will assume a mechanical oscillator in oil where we can work with damping directly proportional to the velocity of the oscillator. Now, we have another equation:

. This equation is also easily analytically solvable, but again we will use Small Math 2D. The solution for the previous initial conditions is on the next image.

Dumped oscillator

Motion in central gravitational field

In this chapter, we will show a way to simulate motion in central gravitational field with Small Math 2D’s 2D ODE solver.

What Wikipedia says about the universal gravitational law: Every object in the Universe attracts every other object with a force directed along the line of centers of mass for the two objects that is proportional to the product of their masses and inversely proportional to the square of the separation between the two objects… …Newton's law of universal gravitation can be written as a vector equation to account for the direction of the gravitational force as well as its magnitude.
Here is the force on object 1 due to object 2, is the gravitational constant, m1 and m2 are the masses of the objects 1 and 2, is the distance between objects 1 and 2, is the unit vector from object 2 to 1.

According to the above written vector equation, the motion in central gravitational field (for two dimensions) can be described by system of two ordinary differential equations:

These equations can be directly solved by 2D ODE solver.

  1. Choose item “2D differential equation” from menu “Plot”.
  2. Type the right sides of above written equations: -x/(x*x + y*y)^1.5 and -y/(x*x + y*y)^1.5 (To make things as easy as possible we assume .
  3. Type the initial conditions, for example x(0) = 1, y(0) = 1, x(0)’ = 0.5, y(0)’ = -0,5.
  4. Set the range for variable t, for example t0 = 0, tend = 150.
  5. Set the number of divisions. (Actually this is not the exact count of iterations because of the use of the adaptive step. It determines only the lower bound of the iterations count).
  6. Press “Draw”.

You should see something like this.

Fourier Series

A Fourier trigonometric series F(t) of a periodic function f(t) with period T is defined as an infinite sum:

For F(t) we may write , as F(t) converges to the function f(t) at points where f(t) is continuous and converges to the arithmetical mean of the left and right limit at points of discontinuity.

In this chapter, we will demonstrate approximation of square wave f(t)=heaviside(sin(t))-heaviside(-sin(t)) (plotted on the image below) by first few terms of its Fourier series.

At first, we must compute the coefficients ak and bk. We can immediately see, that the absolute term a0 is zero, because the definite integral over the period is certainly equal to zero. Coefficients ak are also zeros for all k natural, because f(t) is an odd function. The only thing, which remains undone, is to compute the coefficients bk.

Now, we are ready to display the computed Fourier series of the square wave with Small Math 2D. (We will need the summing function: sum(LowerBound, UpperBound, Expression).)

  1. Choose item Explicit Curve from menu “Plot”.
  2. Type the expression 4/pi*sum(0, 10, 1/(2*n+1)*sin((2*n+1)*x)).
  3. Press “Draw”.

You should be able to see something similar to the image below.

On the next image there is the original function and its approximation for various number of terms of the Fourier series F(t).