You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2013/11/07 20:36:38 UTC

svn commit: r1539775 - in /commons/proper/math/trunk/src/userguide/java/org/apache/commons/math3/userguide/filter: CannonballExample.java ConstantVoltageExample.java

Author: tn
Date: Thu Nov  7 19:36:38 2013
New Revision: 1539775

URL: http://svn.apache.org/r1539775
Log:
Further improvements.

Modified:
    commons/proper/math/trunk/src/userguide/java/org/apache/commons/math3/userguide/filter/CannonballExample.java
    commons/proper/math/trunk/src/userguide/java/org/apache/commons/math3/userguide/filter/ConstantVoltageExample.java

Modified: commons/proper/math/trunk/src/userguide/java/org/apache/commons/math3/userguide/filter/CannonballExample.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/userguide/java/org/apache/commons/math3/userguide/filter/CannonballExample.java?rev=1539775&r1=1539774&r2=1539775&view=diff
==============================================================================
--- commons/proper/math/trunk/src/userguide/java/org/apache/commons/math3/userguide/filter/CannonballExample.java (original)
+++ commons/proper/math/trunk/src/userguide/java/org/apache/commons/math3/userguide/filter/CannonballExample.java Thu Nov  7 19:36:38 2013
@@ -124,15 +124,6 @@ public class CannonballExample {
     
     public static void cannonballTest(Chart chart) {
         
-        // Let's go over the physics behind the cannon shot, just to make sure it's
-        // correct:
-        // sin(45)*100 = 70.710 and cos(45)*100 = 70.710
-        // vf = vo + at
-        // 0 = 70.710 + (-9.81)t
-        // t = 70.710/9.81 = 7.208 seconds for half
-        // 14.416 seconds for full journey
-        // distance = 70.710 m/s * 14.416 sec = 1019.36796 m
-
         // time interval for each iteration
         final double dt = 0.1;
         // the number of iterations to run
@@ -166,7 +157,7 @@ public class CannonballExample {
         final RealVector controlVector =
                 MatrixUtils.createRealVector(new double[] { 0, 0, 0.5 * -9.81 * dt * dt, -9.81 * dt } );
 
-        // The control matrix B only expects y and vy, see control vector
+        // The control matrix B only update y and vy, see control vector
         final RealMatrix B = MatrixUtils.createRealMatrix(new double[][] {
                 { 0, 0, 0, 0 },
                 { 0, 0, 0, 0 },
@@ -178,8 +169,8 @@ public class CannonballExample {
         //
         //  x(n+1) = x(n) + vx(n)
         // vx(n+1) = vx(n)
-        //  y(n+1) = y(n) + vy(n) - 0.5*9.81*dt^2
-        // vy(n+1) = vy(n) + -9.81*dt
+        //  y(n+1) = y(n) + vy(n) - 0.5 * 9.81 * dt^2
+        // vy(n+1) = vy(n) + -9.81 * dt
         //
         // Which, if you recall, are the equations of motion for a parabola.
 

Modified: commons/proper/math/trunk/src/userguide/java/org/apache/commons/math3/userguide/filter/ConstantVoltageExample.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/userguide/java/org/apache/commons/math3/userguide/filter/ConstantVoltageExample.java?rev=1539775&r1=1539774&r2=1539775&view=diff
==============================================================================
--- commons/proper/math/trunk/src/userguide/java/org/apache/commons/math3/userguide/filter/ConstantVoltageExample.java (original)
+++ commons/proper/math/trunk/src/userguide/java/org/apache/commons/math3/userguide/filter/ConstantVoltageExample.java Thu Nov  7 19:36:38 2013
@@ -90,7 +90,7 @@ public class ConstantVoltageExample {
     public static void constantVoltageTest(Chart chart1, Chart chart2) {
 
         final double voltage = 1.25d;
-        final double measurementNoise = 0.1d; // measurement noise (V) - std dev
+        final double measurementNoise = 0.2d; // measurement noise (V) - std dev
         final double processNoise = 1e-5d;
 
         final VoltMeter voltMeter = new VoltMeter(voltage, processNoise, measurementNoise, 2);
@@ -111,7 +111,7 @@ public class ConstantVoltageExample {
         final RealMatrix Q = new Array2DRowRealMatrix(new double[] { processNoise * processNoise });
 
         // the initial error covariance -> assume a large error at the beginning
-        final RealMatrix P0 = new Array2DRowRealMatrix(new double[] { 1 });
+        final RealMatrix P0 = new Array2DRowRealMatrix(new double[] { 0.1 });
 
         // the measurement covariance matrix -> put the "real" variance
         RealMatrix R = new Array2DRowRealMatrix(new double[] { measurementNoise * measurementNoise });
@@ -127,7 +127,7 @@ public class ConstantVoltageExample {
 
         final List<Number> covSeries = new ArrayList<Number>();
         
-        for (int i = 0; i < 200; i++) {
+        for (int i = 0; i < 300; i++) {
             xAxis.add(i);
 
             voltMeter.step();
@@ -138,12 +138,11 @@ public class ConstantVoltageExample {
             final double measuredVoltage = voltMeter.getMeasuredVoltage();
             measuredVoltageSeries.add(measuredVoltage);
 
-            filter.predict();
-            filter.correct(new double[] { measuredVoltage });
-            
             kalmanVoltageSeries.add(filter.getStateEstimation()[0]);
-            
             covSeries.add(filter.getErrorCovariance()[0][0]);
+
+            filter.predict();
+            filter.correct(new double[] { measuredVoltage });
         }
 
         chart1.setYAxisTitle("Voltage");
@@ -199,7 +198,7 @@ public class ConstantVoltageExample {
         JComponent container = new JPanel();
         container.setLayout(new BoxLayout(container, BoxLayout.LINE_AXIS));
         
-        Chart chart1 = createChart("Filter", 550, 450, LegendPosition.InsideNE, true);
+        Chart chart1 = createChart("Voltage", 550, 450, LegendPosition.InsideNE, true);
         Chart chart2 = createChart("Error Covariance", 450, 450, LegendPosition.InsideNE, false);
         
         constantVoltageTest(chart1, chart2);