Tip 81. KISS Principle (by the example of least-squares method)
(Translation into English by Roger H. Faucher, M.A.T. ESL rfauch2001@yahoo.com)
Fig. 81. Universal realization of least-square
method
The KISS
principle is not related to kisses, although it is easy to notice its application
in computer use. KISS is an acronym for the English phrase "Keep It
Simple, Stupid!" It calls for using the simplest algorithm possible when
solving problems. The KISS-principle is a useful one to follow when working
with any program. Certainly, this tip will reduce frustration among Mathcad
users.
The solution of one of the most popular
problems, approximation of tabular dependence by the least-squares method in
Mathcad, is shown in fig. 81. For this purpose,
there are special built-in functions in Mathcad: slope, intercept, line, linfit, genfit, etc… The more universal function is the last one listed– genfit (general fitting), which is
applicable for any type of approximation function with any number of variables.
There is only one defect of genfit – it's use requires a knowledge of partial
derivatives of the approximation function. They can be found with help of
symbolic mathematics. But that’s the trouble, since the variables of the
approximation function have to be written as the elements of a vector (x0, x1 and etc.). But operators and
commands of symbolic mathematics are not applied for such unknowns. Separately
used, the genfit function
hides the calculation and makes it difficult to understand.
As the title of the tip suggests, the problem
can be solved more simply (KISS principle) and more visually if we remember
that it reduces to a minimization of sum of squares points departure from a
curve. There is corresponding built-in function Minimize in Mathcad 8 and in
more recent versions. In fig. 81,
the least-squares method is "clear" and it opens for study: We
find the meaning of the variables b and k where a function with the name Σ[Δ^2] (sum of squares points departure
required in the approximation curve) will be a miminun.
Here are a few more tips: