private IList<State> Solve(State state) { var states = new List<State>(); var dt = Inputs.DeltaT; var ic = IntegrationConstants(); var effectiveK = Inputs.K + ic[0] * Inputs.M + ic[1] * Inputs.C; states.Add(state); for (double t = Inputs.T0; t < Inputs.Tk; t += Inputs.DeltaT*Inputs.Teta) { var lastState = states.Last(); var effectiveR = Inputs.R.ToVector(t) + Inputs.Teta * (Inputs.R.ToVector(t + Inputs.DeltaT) - Inputs.R.ToVector(t)) + Inputs.M * (ic[0] * lastState.MovementU + ic[2] * lastState.SpeedU + 2 * lastState.AccelerationU) + Inputs.C * (ic[1] * lastState.MovementU + 2 * lastState.SpeedU + ic[3] * lastState.AccelerationU); var nextMovementU = effectiveR * effectiveK.Inverse(); var nextAcceleration = ic[4] * (nextMovementU - lastState.MovementU) + ic[5] * lastState.SpeedU + ic[6] * lastState.AccelerationU; var nextSpeed = lastState.SpeedU + ic[7] * (nextAcceleration + lastState.AccelerationU); var nextMove = lastState.MovementU + dt * lastState.SpeedU + ic[8] * (nextAcceleration + 2 * lastState.AccelerationU); states.Add(new State(t, effectiveR, nextMove, nextSpeed, nextAcceleration, nextMovementU)); } return states; }
private State AdjustInitialState(State state, double a2, double a0, double a1, Vector<double> pastU, Matrix<double> effectiveM) { var effectiveR = Inputs.R.ToVector(Inputs.T0) - (Inputs.K - a2 * Inputs.M) * Inputs.MovementU - (a0 * Inputs.M - a1 * Inputs.C) * pastU; var nextStateMovementU = effectiveR * effectiveM.Inverse(); return new State(Inputs.T0, effectiveR, state.MovementU, state.SpeedU, state.AccelerationU, nextStateMovementU); }
private IList<State> Solve(State initState) { var ic = PrepareIntegrationConstants(); var states = new List<State>(); var pastU = initState.MovementU - Inputs.DeltaT * initState.SpeedU + ic[3] * initState.AccelerationU; var effectiveM = ic[0] * Inputs.M + ic[1] * Inputs.C; states.Add(AdjustInitialState(initState, ic[2], ic[0], ic[1], pastU, effectiveM)); for (double t = Inputs.T0 + Inputs.DeltaT; t < Inputs.Tk; t += Inputs.DeltaT) { var previosState = states.Last(); var effectiveR = Inputs.R.ToVector(t) - (Inputs.K - ic[2] * Inputs.M) * previosState.NextStateMovementU - (ic[0] * Inputs.M - ic[1] * Inputs.C) * previosState.MovementU; var nextStateMovementU = effectiveR * effectiveM.Inverse(); var speedU = ic[1] * (nextStateMovementU - previosState.MovementU); var accelerationU = ic[0] * (previosState.MovementU - 2 * previosState.NextStateMovementU + nextStateMovementU); states.Add(new State(t, effectiveR, previosState.NextStateMovementU, speedU, accelerationU, nextStateMovementU)); } return states; }
private void RenderWithInterval(int from, int to, State state) { for (int i = from, j = 0; i <= to; i++, ++j) { if (chart1.Series.Count < j + 1) { chart1.Series.Add(new Series("U" + i) { ChartType = SeriesChartType.Spline, BorderWidth = 3 }); } chart1.Series[j].Points.AddXY(state.Time, state.MovementU[i]); } }
private void RenderMany(IList<int> indexes, State state) { for (int i = 0; i < indexes.Count; ++i) { if (chart1.Series.Count < i + 1) { chart1.Series.Add(new Series("U" + indexes[i]) { ChartType = SeriesChartType.Spline, BorderWidth = 3 }); } chart1.Series[i].Points.AddXY(state.Time, state.MovementU[indexes[i] - 1]); } }