Sign in Join
Wiki copytemporary

LMath: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## About
22
3-LMath is a mathematical library for Free Pascal (FPC) and Lazarus. It's a further development of [[DMath]] from Jean Debord. It is entirely written in Pascal and does not depend on external libraries.
3+LMath is a mathematical library for Free Pascal (FPC) and Lazarus. It's a further development of [[DMath]] from Jean Debord. It is entirely written in Pascal and does not depend on external libraries.
44
5-LMath provides routines and demo programs for numerical analysis, including mathematical functions, probabilities, matrices, optimization, linear and nonlinear equations, integration, Fast Fourier Transform, random numbers, curve fitting, statistics and graphics.
5+LMath provides routines and demo programs for numerical analysis, including mathematical functions, probabilities, matrices, optimization, linear and nonlinear equations, integration, Fast Fourier Transform, random numbers, curve fitting, statistics and graphics.
66
7-Author: Viatcheslav V. Nesterov (glorfin)
7+Author: Viatcheslav V. Nesterov (glorfin)
88
9-License: LGPL 3.0
9+License: LGPL 3.0
1010
1111## Changes from DMath
1212
13-- Naming of packages and units made more systematic. Now names of all units begin from u (for example, uTypes), while names of all packages begin from lm (for example, lmMathUtil). Hence, you will probably change Requirements in your project inspector.
14-- Units uVectorHelper, uVecUtils, uVecFunc and uVecPrn in lmMathUtil package define several handy functions for work with arrays.
15-- Unit uMatrix in lmLineAlgebra defines several general operations over vectors and matrices.
16-- COBYLA algorithm (Constrained Optimization by Linear Approximation, M. Powell) for tasks of constrained optimization included in lmOptimum package, unit uCobyla.
17-- Procedure for constrained non-linear regression ConstrNLFit in the unit uConstrLNFit which uses COBYLA algorithm included in lmRegression package.
18-- Procedure LinProgSolve in the unit uLinSimplex, package lmOptimum implements simplex method for solution of linear programming problems.
19-- Unit uintPoints in lmGenMath package defines operators over TIntPoint, similar to uRealPoints.
20-- Unit uUnitsFormat in lmMathUtils package allows now using of long prefixes (for example, "pico") along with short ("p") ones.
13+ * Units uVectorHelper, uVecUtils, uVecFunc and uVecPrn in lmMathUtil package define several handy functions for work with arrays.
14+ * Unit uMatrix in lmLineAlgebra defines several general operations over vectors and matrices.
15+ * COBYLA algorithm (Constrained Optimization by Linear Approximation, M. Powell) for tasks of constrained optimization included in lmOptimum package, unit uCobyla.
16+ * Procedure for constrained non-linear regression ConstrNLFit in the unit uConstrLNFit which uses COBYLA algorithm included in lmRegression package.
17+ * Procedure LinProgSolve in the unit uLinSimplex, package lmOptimum implements simplex method for solution of linear programming problems.
18+ * Unit uintPoints in lmGenMath package defines operators over TIntPoint, similar to uRealPoints.
19+ * Unit uUnitsFormat in lmMathUtils package allows now using of long prefixes (for example, "pico") along with short ("p") ones.
20+ * Other additions appear as the library evolves.
2121
22-This document describes what is new in LMath compared to DMath: [New in LMath (PDF)](https://sourceforge.net/projects/lmath-library/files/DOC/LMath05/New_in_LMath.pdf/download).
22+## Structure of the library
2323
24+The library is organized as 13 relatively small packages:
25+
26+ * lmGenMath. This package defines several important data structures, used later in the whole library, some utility functions, basic math functions and special functions. All other packages of the library depend on lmGenMath.
27+ * lmMathUtil. Various function for manipulations with arrays, sorting and formatting. Depends on lmGenMath.
28+ * lmLinearAlgebra. Operations over vectors and matrices. Depends on lmMathUtil and lmGenMath.
29+ * lmPolynoms. Evaluation of polynomials, polynomial roots finding, polynomial critical points finding. Depends on lmGenMath and lmLinearAlgebra.
30+ * lmIntegrals. Numeric integrating and solving differential equations. Depends on lmGenMath.
31+ * lmRandoms. Generation of random numbers. Depends on lmGenMath.
32+ * lmMathStat. Descriptive statistics, hypothesis testing, collection of various distributions. Depends on lmGenMath and lmLinearAlgebra.
33+ * lmOptimum. Algorithms of function minimization. Somewhat artificially, unit uEval for evaluation of an expression, is included into this package. Depends on lmGenMath, lmLinearAlgebra, lmRandoms, lmMathStat.
34+ * lmNonLinEq. Finding roots of non-linear equations. Depends on lmGenMath, lmLinearAlgebra, lmOptimum.
35+ * lmDSP. Functions for digital signal processing. Convolution, collection of filters and Fourier Transform procedures.
36+ * lmRegression. Functions for linear and non-linear regression, curve fitting. Collection of common models. Depends on lmLinearAlgebra, lmPolynoms, lmOptimum, lmMathUtil.
37+ * lmSpecRegress. Collection of field-specific models for data fitting. Depends on lmGenMath and lmRegression.
38+ * lmPlotter. Routines for data and functions plotting. Depends on lmGenMath, lmMathUtil and LCL.
39+
2440## Download
2541
26-- [SourceForge](https://sourceforge.net/projects/lmath-library).
42+ * [SourceForge](<https://sourceforge.net/projects/lmath-library>).
2743
44+## Installation
45+
46+Download and unpack file "LMath_and_Components_x_x_x.zip". Open and compile packages:
47+
48+ * lmGenMath,
49+ * lmMathUtil,
50+ * lmLinearAlgebra,
51+ * lmPolynoms,
52+ * lmIntegrals,
53+ * lmRandoms,
54+ * lmMathStat,
55+ * lmOptimum,
56+ * lmNonLinEq,
57+ * lmRegression,
58+ * lmSpecRegress,
59+ * lmDSP,
60+ * lmPlotter,
61+
62+in this order. Afterwards you may compile LMath.pkg, which does not have any additional code but simply depends on all these packages. Therefore, if you add dependency on LMath to your project, it is not necessary to add every single package.
63+
64+Alternatively, if you have Project Groups package installed in your Lazarus IDE, you can open and compile LMath project group, select LMath target and compile it.
65+
66+You do not need to install LMath in the IDE, simply add packages to the dependencies of your project and needed units to the _uses_ clause of your units.
67+
68+If you are going to use LMComponents, open LMComponents package, compile and install it.
69+
70+## LMComponents
71+
72+LMComponents is included in the LMath distro. It contains units:
73+
74+### Unit lmPointsVec
75+
76+TPoints is a class wrapper around TRealPointVector (see LMath.pdf, Chapter 2). Its properties X[index] and Y[index] provide access to X and Y fields as to separate arrays of Float; if the package was compiled with -dDebug setting, range check is done for Index. However, use of X and Y properties has a considerable penalty on performance. Direct access to underlying array TPoints.Points is provided for use in time-critical code sections, but in general it is safer to use X and Y properties. If Append procedure is used for adding new points, Count is adjusted automatically; by exceeding current Capacity, memory is automatically reallocated. In addition, many utility methods and properties are provided, such as MaxX, MaxY, MinX, MinY; RemovePoints allows to remove subarray from an arbitrary index; constructor Combine allows to create TPoints from two vectors of Float; opposite to it, Extract is a mean to extract X or Y as vector of Float; SortX and SortY sort Points as names suggest.
77+
78+### Unit lmFilters
79+
80+Unit lmFilters includes several digital filters of a signal. They are implemented as non-visual components:
81+
82+ * TDigFilter. Ancestor class for all digital filters.
83+ * TOneFreqFilter. Ancestor class for all filters with a single corner frequency.
84+ * TFIRFilter. Ancestor class for filters with finite impulse responce filters.
85+ * TMovAvFilter. Moving average filter
86+ * TGaussFilter. Gaussian filter. The only one, which can be used only for filtering ready data, but not real time.
87+ * TMedianFilter. Median filter.
88+
89+Most of them can be used both for filtering of earlier sampled data and for filtering in real time, during data acquisition. To make the components format-independent, data points are fed into filter with user-defined OnInput event and returned by another user-defined OnOutput event. You can drop a component onto a form and define OnInput and OnOutput events. Afterwards, set sampling rate and cut-off frequency by call of SetupFilter method. For moving average filter, one has an alternative to define averaging window length instead of defining sampling rate and cut-off frequency. For median filter, this is the only possibility, because for this filter cut-off frequency is not defined. After setting up the filter properties, either call Filter method for off-line filtering of existing data, or initiate filtering in real time. To do so, call InitFiltering once, and then call NextPoint method whenever new datapoint is aquired. Method Filter calls OnInput event when needs a next input value, and OnOutput when it is ready to return a next output value. Similarly, NextPoint calls OnInput and OnOutput when is invoked. This technique with OnInput and OnOutput events makes the components independent of a format of data which are filtered.
90+
91+Implemented are gaussian filter, moving average filter, which are probably the best “smoothing” filters for time domain, and median filter which is ideal to remove short spikes preserving sharp edges. One-pole high-pass filter, notch filter and Chebyshev filter are implemented in lmRecursFilters unit. All of these filters except Gaussian can be used for both real time and off-line filtering. Gaussian filter requires forward and backward filtering, hence, can be used only off line.
92+
93+### Unit lmRecursFilters
94+
95+Several components implementing infinite impulse response filters are defined in this unit:
96+
97+ * THighPassFilter
98+ * TNarrowBandFilter
99+ * TNotchFilter
100+ * TBandPassFilter
101+ * TChebyshevFilter
102+
103+### Unit lmCoordSys
104+
105+TCoordSys component implemented in this unit is relatively simple Cartesian coordinate plane for drawing points, lines, graphical primitives and mathematical functions in user’s coordinates. Component is derived from TPanel, so, you can place other components, for example, scale edits, on top of it.
106+
107+Usage: place the component on your form, in the Object Inspector define positions of axes, distance between grid lines (in user space) as well as coordinate limits (MinX, MaxX, MinY, MaxY). Define TPen properties which are used for drawing axes, grid lines and user data, as well as numeric format for axis numbering.
108+
109+For drawing of user’s data define OnDrawData event; all your drawing must occur within it.
110+
111+Coordinates are converted between user space and screen coordinates with UserToScreen, ScreenToUser, XUserToScreen, YUserToScreen, XScreenToUser and YScreenToUser functions, but you seldom need to call them directly. Procedures PutLine, GoToXY, LineTo, Circle, Aim, FillRect are provided for drawing graphical primitives and data in user’s space. Procedure FastDraw serves for fast drawing of arrays of TPoint sorted for X coordinate; DrawSpline and DrawFunc provide plotting of data and mathematical functions.
112+
113+Canvas property is published, allowing to define easily own drawing procedures. All drawing of user’s data must occur in OnDrawData event, which is called from Paint procedure.
114+
115+### Unit lmNumericEdits
116+
117+ * TFloatEdit class
118+
119+### Unit lmNumericInputDialogs
120+
121+ * function IntervalQuery
122+ * function FloatInputDialog
123+
124+## Comparision with AlgLib
125+
126+Q: I'm trying to use some math libraries in my apps. What is the advantage of LMath compared to, for example, ALGLIB (Free Edition)? Maybe it's got something to do with the license or the open source code or what?
127+
128+A (glorfin): Well, license, yes. Free AlgLib is distributed under strict GPL, while LMath under modified LGPL. Besides, in my view, it is easier to use. At list, when I was not yet supporter of LMath and was choosing between AlgLib and DMath for my own project (Nest-o-Patch, <https://sourceforge.net/projects/nestopatch/>, I found building DMath much easier, and LMath is organized as set of Lazarus packages, which makes it even more easy. LMath includes some components; I think that filtering components may be most interesting among them. Package MathUtils makes (in my view) easier work with arrays of real numbers.
129+
130+Having said all that, I don't think, one can say that LMath is better than AlgLib; it is largely question of taste and one's needs. For example, in many cases AlgLib is written in more efficient way and can be preferred for really intensive calculations (though it is also question of testing); procedures in LMath are often easier to understand, exactly because they are not obscured by heavy optimizations.
131+
28132## See also
29133
30-- [[Portal:SciTech|SciTech Portal]]
134+Comprehensive documentation about LMath and LMComponents in pdf form:
31135
136+ * [Reference to LMath_6_1](<https://sourceforge.net/projects/lmath-library/files/DOC/LMath0_6_1.pdf/download>)
137+ * [Reference and manual to LMComponents](<https://sourceforge.net/projects/lmath-library/files/DOC/LMComponents.pdf/download>)
138+ * [Original manual to DMath, includes some theory](<https://sourceforge.net/projects/lmath-library/files/DOC/dmath.pdf/download>)
139+
140+ * [[Portal:SciTech|SciTech Portal]]
141+
32142---
33-*From the Free Pascal wiki, page "LMath", as it stood on 2020-09-10 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
34-Category: FPC
35-Category: FPC in Science and Technology
36-Category: Mathematics
37-Category: Packages
38-Category: SciTech
143+*From the Free Pascal wiki, page "LMath", as the Internet Archive kept it on 2025-01-16, last changed on 2024-10-02. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history