Further improvements.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1539775 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
346a41fc6b
commit
6b18e3897a
|
@ -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.
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
kalmanVoltageSeries.add(filter.getStateEstimation()[0]);
|
||||
covSeries.add(filter.getErrorCovariance()[0][0]);
|
||||
|
||||
filter.predict();
|
||||
filter.correct(new double[] { measuredVoltage });
|
||||
|
||||
kalmanVoltageSeries.add(filter.getStateEstimation()[0]);
|
||||
|
||||
covSeries.add(filter.getErrorCovariance()[0][0]);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue