Hands-On Math

Last Revision March, 2011

Last Revision March, 2011

The following four graphs illustrate the use of k*sin(x) + j*sin(3x) to approximate a semicircle on the interval x = 0 to x = π. At top left,

Even argument sine functions are not of use because they have odd symmetry on this interval.

Relatively smooth objectives such as the semicircle tend to require more amplitude for lower frequencies than higher in their approximation. For this reason a diminishing sequence of initial coefficients was selected as 1, 1/2, 1/3, , , , , 1/17 for the approximating sine series. Reasonable starting values tend to reduce the number of calculation steps required to determine optimal coefficient values.

Objectives that contain sharp edges or spikes tend to employ more uniform coefficient values.

The semicircle was approximated in steps of π/80 over the interval x = 0 to x
= π. Values of the semicircle and its approximation, and the squared error between the two are shown in the
table that follows. Coefficients were optimized one after the other with no
noticeable interaction.

A**macro**, a software program that runs in the Excel spread
sheet and behaves much like a user designed function,
to be described in detail, was employed.

A

Also shown is the sum of the squared errors, the chosen objective function. This objective function is quite commonly used. One reason for the prevalence of this objective function is that substantial difficulties are encountered if one tries to employ most other objective functions when analytic, as opposed to numerical, approximations are attempted. Another reason is its optimality in applications to fitting randomly perturbed data.

The fully optimized approximation is shown in graph form next.

Some coefficients required more adjustment steps than others, some needed 81 steps: the fewest number was 54.

A macro was used in this topic to automate the adjustment of the coefficients so as to minimize the error. This is a task that can be accomplished by a great many sequential by-hand adjustments.

Excel2000 provides an Add-In, Solver, which could have been used to make the adjustments. In our case we use a macro to illustrate how the automation could be accomplished in the absence of Solver.

Moreover, there can be situations in which a more specific adjustment tool is needed and the only way to proceed is to design one's own tool, a macro.

The macro that was used to adjust the coefficients to minimize the error is now shown. Most spreadsheets will provide macro capability. However, the code used to write the macro may differ from Visual Basic, the programming language that was used for this macro. Some knowledge of VB could be required should one want to implement this macro in another programming language. The extensive commenting should be a great help.

The use of

Try to create an improved version of this macro that is easier to use, and, possibly quicker to converge.

Approximation with sinusoids is widespread in Physics and Engineering, particularly in association with studies in thermal conduction, mechanical design, acoustics and communications.