Difference between revisions of "ApCoCoA-1:Num.SavGol"

From ApCoCoAWiki
(New page: <command> <title>Num.SavGol</title> <short_description>Compute numerical derivatives of given time series using the Savitzky-Golay method.</short_description> <syntax> SavGol(Points: MA...)
 
m (insert version info)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{Version|1}}
 
<command>
 
<command>
 
   <title>Num.SavGol</title>
 
   <title>Num.SavGol</title>
  
<short_description>Compute numerical derivatives of given time series using the Savitzky-Golay method.</short_description>
+
<short_description>Compute numerical derivatives of equally spaced data using local polynomial regression.</short_description>
 
<syntax>
 
<syntax>
 
SavGol(Points: MAT, MaxDiffOrd:INT, Nl:INT, Nr:INT, Deg:INT, Mode, StepWidth:RAT)
 
SavGol(Points: MAT, MaxDiffOrd:INT, Nl:INT, Nr:INT, Deg:INT, Mode, StepWidth:RAT)
Line 11: Line 12:
 
<em>Please note:</em> The function(s) explained on this page is/are using the <em>ApCoCoAServer</em>. You will have to start the ApCoCoAServer in order to use it/them.
 
<em>Please note:</em> The function(s) explained on this page is/are using the <em>ApCoCoAServer</em>. You will have to start the ApCoCoAServer in order to use it/them.
 
<par/>
 
<par/>
This command computes numerical derivatives of given time series.
+
This command computes numerical derivatives of given data series assuming that the data points are equally spaced.
 
<par/>
 
<par/>
TODO
+
Each data series is considered as a column of the matrix Points. It is assumed that the spacing StepWidth is the same for all columns. The polynomial degree <tt>Deg</tt> must be less than the window size <tt>Nl+Nr+1</tt>. The derivatives are computed up to order <tt>MaxDiffOrd</tt>.
 
+
The resulting matrix has <tt>Nl+Nr</tt> rows less than Points and has <tt>MaxDiffOrd+1</tt> times more columns as Points. The first <tt>MaxDiffOrd+1</tt> columns correspond to the 0-th, 1-st,...,<tt>MaxDiffOrd</tt>-th derivatives of the first column of Points, and so on.
 
<itemize>
 
<itemize>
<item>@param <em>Points</em> The points for which a border basis is computed.</item>
+
<item>@param <em>Points</em> The data points for which numerical derivatives are computed, each data series is considered as a column.</item>
<item>@param <em>GoUpToOrder</em> The order up to which derivatives are taken to construct the model polynomials. It must be between 0 and the maximal differential order MaxOrd in the definition of the current ring.</item>
+
<item>@param <em>MaxDiffOrd</em> The order up to which derivatives are computed.</item>
<item>@param <em>Epsilon</em> A positive rational number describing the maximal admissible least squares error for a polynomial. (Bigger values for <tt>Epsilon</tt> lead to bigger errors of the polynomials evaluated at the point set). <tt>Epsilon</tt> should be in the interval (0,1). As a rule of thumb, <tt>Epsilon</tt> is the expected percentage of error on the input points. </item>
+
<item>@param <em>Nl</em> Number of left data points to be considered.</item>
<item>@param <em>Nl</em> Number of left data points to be considered by the Savitzky-Golay filter.</item>
+
<item>@param <em>Nr</em> Number of right data points to be considered.</item>
<item>@param <em>Nr</em> Number of right data points to be considered by the Savitzky-Golay filter.</item>
+
<item>@param <em>Deg</em> Maximum degree of the interpolation polynomal. Must be greater or equal MaxOrd.
<item>@param <em>Deg</em> Maximum degree of the interpolation polynomial used by Savitzky-Golay filter. Must be greater or equal MaxOrd.
 
 
</item>
 
</item>
<item>@param <em>CopyReplace</em> Only meaningful, if DoSavGol = 1. Is either <tt>c</tt> or <tt>r</tt>. Use <tt>c</tt> to include (copy) the original time series into the result. Use <tt>r</tt> to replace the original time series by the filtered results from Savitzky-Golay.</item>
+
<item>@return A matrix that represents the derivatives of Points up to order <tt>MaxDiffOrd</tt>.</item>
<item>@param <em>DoSavGol</em> Either 0 or 1. Use 0 if the given Points already contain the numerical derivatives up to the required order. Use 1 if the Savitzky-Golay method should be applied to the given Points.</item>
 
<item>@return The border basis as a list of polynomials.</item>
 
 
</itemize>
 
</itemize>
  
  
 
<example>
 
<example>
Use Q[x[1..2,0..3]];
+
Points := Mat([[ Fn.SinN(I/2, 10), Fn.CosN(I/2, 10) ] | I In 0..40 ]);
Use Q[x[1..2,0..3]], Ord(DA.DiffTO(<quotes>Ord</quotes>));
 
 
 
 
 
Nl := 2;
 
Nr := 2;
 
Deg := 4;
 
 
 
GoUpToOrder := 2;
 
 
 
Epsilon:=0.1;
 
 
 
CopyReplace := "c";
 
DoSavGol := 1;
 
 
 
-- Data is given by [[cos(I), sin(I)] | I In 1..35].
 
Points := Mat([[0.540302, 0.841471], [-0.416147, 0.909297], [-0.989992, 0.14112], [-0.653644, -0.756802], [0.283662, -0.958924],
 
              [0.96017, -0.279415], [0.753902, 0.656987], [-0.1455, 0.989358], [-0.91113, 0.412118], [-0.839072, -0.544021],
 
              [0.0044257, -0.99999], [0.843854, -0.536573], [0.907447, 0.420167], [0.136737, 0.990607], [-0.759688, 0.650288],
 
              [-0.957659, -0.287903], [-0.275163, -0.961397], [0.660317, -0.750987], [0.988705, 0.149877], [0.408082, 0.912945],
 
              [-0.547729, 0.836656], [-0.999961, -0.00885131], [-0.532833, -0.84622], [0.424179, -0.905578], [0.991203, -0.132352],
 
              [0.646919, 0.762558], [-0.292139, 0.956376], [-0.962606, 0.270906], [-0.748058, -0.663634], [0.154251, -0.988032],
 
              [0.914742, -0.404038], [0.834223, 0.551427], [-0.0132767, 0.999912], [-0.84857, 0.529083], [-0.903692, -0.428183]
 
              ]);
 
  
 +
MaxDiffOrd := 3;
 +
Nl := 4;
 +
Nr := 4;
 +
Deg := 3;
 +
Mode := 0; -- Mode is currently not used!
 +
StepWidth := 0.5;
  
Result:=Num.DABM(Points, GoUpToOrder, Epsilon, Nl, Nr, Deg, CopyReplace, DoSavGol);
+
Result := Num.SavGol(Points, MaxDiffOrd, Nl, Nr, Deg, Mode, StepWidth);
Foreach X In Result Do
+
Dec(Result, 2); ]])
  PrintLn Dec(X,2);
 
EndForeach;
 
  
 
-- (Result) --
 
-- (Result) --
 
+
Mat([
1 x[1,1] +0.99 x[2,0] -0.00 x[1,0] +0.00 
+
  [<quote>0.84</quote>, <quote>0.40</quote>, <quote>0.63</quote>, <quote>0.31</quote>, <quote>0.38</quote>, <quote>0.87</quote>, <quote>0.29</quote>, <quote>0.69</quote>]
1 x[2,1] +0.00 x[2,0] -0.99 x[1,0] +0.00 
+
  [<quote>0.55</quote>, <quote>0.77</quote>, <quote>0.41</quote>, <quote>0.61</quote>, <quote>0.74</quote>, <quote>0.57</quote>, <quote>0.56</quote>, <quote>0.45</quote>]
 
[...]
 
[...]
  
Line 71: Line 50:
  
 
     <seealso>
 
     <seealso>
       <see>Introduction to CoCoAServer</see>
+
       <see>ApCoCoA-1:Num.DABM|Num.DABM</see>
      <see>Num.ABM</see>
 
      <see>Num.CABM</see>
 
      <see>Num.BBABM</see>
 
 
     </seealso>
 
     </seealso>
 
     <types>
 
     <types>
Line 80: Line 56:
 
       <type>points</type>
 
       <type>points</type>
 
     </types>
 
     </types>
     <key>DABM</key>
+
     <key>SavGol</key>
     <key>Num.DABM</key>
+
     <key>Num.SavGol</key>
     <key>numerical.DABM</key>
+
     <key>numerical.SavGol</key>
     <wiki-category>Package_numerical</wiki-category>
+
     <wiki-category>ApCoCoA-1:Package_numerical</wiki-category>
 
   </command>
 
   </command>

Latest revision as of 10:30, 7 October 2020

This article is about a function from ApCoCoA-1.

Num.SavGol

Compute numerical derivatives of equally spaced data using local polynomial regression.

Syntax

SavGol(Points: MAT, MaxDiffOrd:INT, Nl:INT, Nr:INT, Deg:INT, Mode, StepWidth:RAT)

Description

Please note: The function(s) explained on this page is/are using the ApCoCoAServer. You will have to start the ApCoCoAServer in order to use it/them.

This command computes numerical derivatives of given data series assuming that the data points are equally spaced.

Each data series is considered as a column of the matrix Points. It is assumed that the spacing StepWidth is the same for all columns. The polynomial degree Deg must be less than the window size Nl+Nr+1. The derivatives are computed up to order MaxDiffOrd.

The resulting matrix has Nl+Nr rows less than Points and has MaxDiffOrd+1 times more columns as Points. The first MaxDiffOrd+1 columns correspond to the 0-th, 1-st,...,MaxDiffOrd-th derivatives of the first column of Points, and so on.

  • @param Points The data points for which numerical derivatives are computed, each data series is considered as a column.

  • @param MaxDiffOrd The order up to which derivatives are computed.

  • @param Nl Number of left data points to be considered.

  • @param Nr Number of right data points to be considered.

  • @param Deg Maximum degree of the interpolation polynomal. Must be greater or equal MaxOrd.

  • @return A matrix that represents the derivatives of Points up to order MaxDiffOrd.


Example

Points := Mat([[ Fn.SinN(I/2, 10), Fn.CosN(I/2, 10) ] | I In 0..40 ]);

MaxDiffOrd := 3;
Nl := 4;
Nr := 4;
Deg := 3;
Mode := 0; -- Mode is currently not used!
StepWidth := 0.5;

Result := Num.SavGol(Points, MaxDiffOrd, Nl, Nr, Deg, Mode, StepWidth);
Dec(Result, 2); ]])

-- (Result) --
Mat([
  [<quote>0.84</quote>, <quote>0.40</quote>, <quote>0.63</quote>, <quote>0.31</quote>, <quote>0.38</quote>, <quote>0.87</quote>, <quote>0.29</quote>, <quote>0.69</quote>]
  [<quote>0.55</quote>, <quote>0.77</quote>, <quote>0.41</quote>, <quote>0.61</quote>, <quote>0.74</quote>, <quote>0.57</quote>, <quote>0.56</quote>, <quote>0.45</quote>]
[...]

See also

Num.DABM