public static void getSingle(IApplicationBuilder app) { app.Run(async context => { try { var input = SingleXInput.getFromRequest(context); var lagrange = new LagrangeMethod(); var differentialValues = DiffirentialEquationSolver.lastValues; double[] resx = new double[differentialValues.Count]; double[] resy = new double[differentialValues.Count]; for (int i = 0; i < differentialValues.Count; i++) { resx[i] = differentialValues[i].X; resy[i] = differentialValues[i].Y; } var result = lagrange.getY(resx, resy, input.X); await context.Response.WriteAsync(result.ToString()); } catch (Exception ex) { await context.Response.WriteAsync(ex.Message); } }); }
public Interpolater(double offset) { _repo = new FunctionRepository(); _lagrange = new LagrangeMethod(); FuncInit(); this.offset = offset; }
public Interpolater(double offset, int pointToChangeIndex, double step) { _repo = new FunctionRepository(); _lagrange = new LagrangeMethod(); FuncInit(); this.offset = offset; this.pointToChangeIndex = pointToChangeIndex; this.step = step; }
public static void Update(DiffirentialEquationInput input) { _lagrange = new LagrangeMethod(); _newton = new NewtonMethod(); _repo = new FunctionRepository(); FuncInit(); X0 = input.X0; XN = input.XN; Y0 = input.Y0; Accuracy = input.Accuracy; FuncType = input.FuncType; }
public void DrawInterpolation(LambdaFunc func, float step) { DrawFunction((x) => (float)(50 * func(x / 100) + 100), Color.Black); double[] pointsX = new double[] { 0, Math.PI / 2, Math.PI, Math.PI * 3 / 2, Math.PI * 2 }; double[] pointsY = new double[] { func(pointsX[0]), func(pointsX[1]), func(pointsX[2]), func(pointsX[3]), func(pointsX[4]) }; DrawFunction((x) => (float)(50 * NewtonMethod.Newton(x / 100, pointsX, pointsY, (float)step) + 100), Color.Red); DrawFunction((x) => (float)(50 * LagrangeMethod.Langrange(x / 100, pointsX, pointsY, (float)step - 0.6f) + 100), Color.Green); }
private void updateSolutions() { // make the grid view apply it's changes to it's data cache dataGridViewSamplesInput.EndEdit(); clearDataGridDuplicateEnteries(); // consider only valid visible rows, because invisible rows are deleted but cannot be // completely removed because of a weird exception List <DataGridViewRow> validRows = new List <DataGridViewRow>(); for (int i = 0; i < dataGridViewSamplesInput.Rows.Count; i++) { if (dataGridViewSamplesInput.Rows[i].Visible) { validRows.Add(dataGridViewSamplesInput.Rows[i]); } } // check if the input is complete bool twoColumnsCompleteInput = true; int twoColumnsCompleteRowsCounter = 0; for (int i = 0; i < validRows.Count; i++) { DataGridViewRow currentRow = validRows[i]; // if only one of the cells in the row has a value and the other doesn't if (cellDoesntHaveValue(currentRow.Cells[samplesXIndex]) ^ cellDoesntHaveValue(currentRow.Cells[samplesYIndex])) { twoColumnsCompleteInput = false; } // if the row is not empty then count it if (cellHasValue(currentRow.Cells[samplesXIndex])) { twoColumnsCompleteRowsCounter++; } } // make sure that the input we have is full before we start to collect samples if (twoColumnsCompleteInput && twoColumnsCompleteRowsCounter > 0) { double[,] twoColumnsInterpolationSamples = new double[2, twoColumnsCompleteRowsCounter]; // collect samples from the grid view for (int i = 0; i < validRows.Count; i++) { DataGridViewRow currentRow = validRows[i]; if (cellHasValue(currentRow.Cells[samplesXIndex])) { twoColumnsInterpolationSamples[samplesXIndex, i] = double.Parse(currentRow.Cells[samplesXIndex].Value.ToString()); twoColumnsInterpolationSamples[samplesYIndex, i] = double.Parse(currentRow.Cells[samplesYIndex].Value.ToString()); } } // clear results view textBoxOutputResults.Clear(); // General Method Code GeneralMethodFunction generalMethod = new GeneralMethodFunction(twoColumnsInterpolationSamples); if (generalMethod.isSolvable && checkBoxGeneralMethod.Checked) { textBoxOutputResults.AppendText("General Method's Solution:"); textBoxOutputResults.Text += "\r\n\r\n"; textBoxOutputResults.AppendText(generalMethod.FunctionString); if (stringNotEmpty(textBoxPerdictValue.Text)) { textBoxOutputResults.Text += "\r\n\r\n"; textBoxOutputResults.AppendText(generalMethod.YForXString(textBoxPerdictValue.Text)); } textBoxOutputResults.Text += "\r\n\r\n"; } // end of general method // Lagrange method code LagrangeMethod lagrangeMethod = new LagrangeMethod(twoColumnsInterpolationSamples); if (lagrangeMethod.isSolvable && checkBoxLagrangeMethod.Checked) { textBoxOutputResults.AppendText("Lagrange Method's Solution:"); textBoxOutputResults.Text += "\r\n\r\n"; textBoxOutputResults.AppendText(lagrangeMethod.FunctionString); if (stringNotEmpty(textBoxPerdictValue.Text)) { textBoxOutputResults.Text += "\r\n\r\n"; textBoxOutputResults.AppendText(lagrangeMethod.YForXString(textBoxPerdictValue.Text)); if (stringNotEmpty(textBoxLagrangeDifferential.Text)) { textBoxOutputResults.Text += "\r\n\r\n"; textBoxOutputResults.AppendText(lagrangeMethod.ErrorStringForX(textBoxPerdictValue.Text, textBoxLagrangeDifferential.Text)); } } textBoxOutputResults.Text += "\r\n\r\n"; } // end of Lagrange method's code // Lagrange differentiation method code LagrangeDiffrentiationMethod lagrangeDifferentialMethod = new LagrangeDiffrentiationMethod(twoColumnsInterpolationSamples); if (lagrangeDifferentialMethod.isSolvable && checkBoxLagrangeDifferentiation.Checked) { textBoxOutputResults.AppendText("Lagrange's differential Method's Solution:"); textBoxOutputResults.Text += "\r\n\r\n"; textBoxOutputResults.AppendText(lagrangeDifferentialMethod.FunctionString); if (stringNotEmpty(textBoxPerdictValue.Text)) { textBoxOutputResults.Text += "\r\n\r\n"; textBoxOutputResults.AppendText(lagrangeDifferentialMethod.YForXString(textBoxPerdictValue.Text)); } textBoxOutputResults.Text += "\r\n\r\n"; } // end of Lagrange differentiation method's code #warning add your two columns (x, y) method calling code here // hermit method code bool ThreeColumnsInputComplete = true; int ThreeColumnCompleteRowsCounter = 0; if (!checkBoxHermitMethod.Checked) { ThreeColumnsInputComplete = false; } else { // check the y' column for complete input for (int i = 0; i < validRows.Count; i++) { DataGridViewRow currentRow = validRows[i]; DataGridViewCell currentCell = currentRow.Cells[samplesYDerivativeIndex]; DataGridViewCell comparedRandomCell = currentRow.Cells[samplesXIndex]; // since at this point we are sure we have a complete input for methods other that hermit // (i.e X's and Y's columns are complete) we only need to check one cell other that the Y' cell // to see if that row has any values if (cellDoesntHaveValue(currentCell) ^ cellDoesntHaveValue(comparedRandomCell)) { ThreeColumnsInputComplete = false; } if (cellHasValue(currentCell)) { ThreeColumnCompleteRowsCounter++; } } } if (ThreeColumnsInputComplete && ThreeColumnCompleteRowsCounter > 0) { double[,] threeColumnsInterpolationSamples = new double[3, twoColumnsCompleteRowsCounter]; // collect samples for hermit from the grid view for (int i = 0; i < validRows.Count; i++) { DataGridViewRow currentRow = validRows[i]; if (cellHasValue(currentRow.Cells[samplesXIndex])) { threeColumnsInterpolationSamples[samplesXIndex, i] = double.Parse(currentRow.Cells[samplesXIndex].Value.ToString()); threeColumnsInterpolationSamples[samplesYIndex, i] = double.Parse(currentRow.Cells[samplesYIndex].Value.ToString()); threeColumnsInterpolationSamples[samplesYDerivativeIndex, i] = double.Parse(currentRow.Cells[samplesYDerivativeIndex].Value.ToString()); } } #warning add your three columns (x, y, y') method calling code here HermitMethod hermitMethod = new HermitMethod(threeColumnsInterpolationSamples); if (hermitMethod.isSolvable) { textBoxOutputResults.AppendText("Hermit Method's Solution:"); textBoxOutputResults.Text += "\r\n\r\n"; textBoxOutputResults.AppendText(hermitMethod.FunctionString); if (stringNotEmpty(textBoxPerdictValue.Text)) { textBoxOutputResults.Text += "\r\n\r\n"; textBoxOutputResults.AppendText(hermitMethod.YForXString(textBoxPerdictValue.Text)); textBoxOutputResults.Text += "\r\n\r\n"; if (stringNotEmpty(textBoxHermitDifferential.Text)) { textBoxOutputResults.AppendText(hermitMethod.ErrorStringForX(textBoxPerdictValue.Text, textBoxHermitDifferential.Text)); } } textBoxOutputResults.Text += "\r\n\r\n"; } } // end of hermit's code //Spline Method Code SplineMethod splinemethod = new SplineMethod(twoColumnsInterpolationSamples); if (splinemethod.isSolvable && checkBoxSplineMethod.Checked) { textBoxOutputResults.AppendText("Spline Method's Solution:"); textBoxOutputResults.Text += "\r\n\r\n"; textBoxOutputResults.AppendText(splinemethod.FunctionString); if (stringNotEmpty(textBoxPerdictValue.Text)) { textBoxOutputResults.Text += "\r\n\r\n"; textBoxOutputResults.AppendText(splinemethod.YForXString(textBoxPerdictValue.Text)); } } //end of spline's method } }