public RAlgSolver(TaskWorker tw, RKResults res, List<List<double>> startParameters, Vector startP, int method) : this(tw, res, startParameters) { this.startP = startP; if (this.startP.Count == 1) { calcFunct += CalcFunct1; } else { if (method == 0) { calcFunct += CalcFunct2; } else { calcFunct += CalcFunct2_1; } } }
private RAlgSolver(TaskWorker tw, RKResults res, List<List<double>> startParameters) { this.tw = tw; this.res = res; itab = new int[res.Count - 1]; if (res[0].Y.Count == 2) { var dz1 = new double[res.Count - 1]; for (int i = 1; i < res.Count; i++) { dz1[i - 1] = (res[i].Y[0] - res[i - 1].Y[0]) / (res[i].X - res[i - 1].X); } var dz2 = new double[res.Count - 2]; for (int i = 1; i < dz1.Length; i++) { dz2[i - 1] = (dz1[i] - dz1[i - 1]) / (res[i].X - res[i - 1].X); } dz = dz2; } var list = new List<TaskParameter>(); int k = 0; for (int i = 0; i < startParameters.Count; i++) { var tp1 = new TaskParameter(startParameters[i].Count); for (int j = 0; j < startParameters[i].Count; j++) { x[k] = startParameters[i][j]; tp1.Param[j] = x[k]; k++; } list.Add(tp1); } c = k; tp = new TaskParameters(list, double.MinValue); }
public RAlgSolver(TaskWorker tw, RKResults res, List<List<double>> startParameters, double[] dz) : this(tw, res, startParameters) { this.dz = dz; }
private RKResults DrawRes(RKResults r, RAlgSolver ra, string cn, string cnsuff, Color c, OutputHelper output, int eb, out double functional) { if (!isReal) { for (int i = 0; i < r.Count - setCount; i++) { if (eb == 1) { if (setCount == 1) { (tblResList as List<ResPointViewType1>)[i + i*step].M1 = ra.itab[i]; } else { (tblResList as List<ResPointViewType2>)[i + i*step].M1 = ra.itab[i]; } } else { if (setCount == 1) { (tblResList as List<ResPointViewType1>)[i + i*step].M2 = ra.itab[i]; } else { (tblResList as List<ResPointViewType2>)[i + i*step].M2 = ra.itab[i]; } } } grcTabRes.RefreshDataSource(); } var sb = new StringBuilder(); Dictionary<double, int> tt = GetTT(r, ra.itab); //-- draw res --- if (!curves.ContainsKey(cn)) { curves.Add(cn, new PointPairList()); var curve = new LineItem(cn, curves[cn], c, SymbolType.None); curve.Line.Style = DashStyle.Dash; curve.Line.Width = 2; //this.zgcMainChart2.MasterPane[1].CurveList.Add(curve); if (setCount == 2) { curves.Add(cn + cnsuff, new PointPairList()); var curve1 = new LineItem(cn + cnsuff, curves[cn + cnsuff], c, SymbolType.None); curve.Line.Style = DashStyle.Dash; curve.Line.Width = 2; zgcMainChart2.MasterPane[0].CurveList.Add(curve1); zgcMainChart2.MasterPane[1].CurveList.Add(curve); } else { zgcMainChart2.MasterPane[0].CurveList.Add(curve); } } else { curves[cn].Clear(); if (setCount == 2) { curves[cn + cnsuff].Clear(); } } int k = 0; var listDraw = new List<TaskParameter>(); for (int i = 0; i < tps.Count; i++) { var tpDraw = new TaskParameter(tps[i].Param.Length); string line = string.Format("{0}) ", i); for (int j = 0; j < tps[0].Param.Length; j++) { tpDraw.Param[j] = ra.x[k]; line += string.Format("a{0}={1:f6} ", j, ra.x[k]); k++; } sb.AppendLine(line); listDraw.Add(tpDraw); } sb.AppendLine("-----"); var tps1 = new TaskParameters(listDraw, tt); var tw1 = new TaskWorker(tps1, funcDescr.GetType(), funcDescr.MainFuncName, funcDescr.SecFuncName, funcDescr); double t0, t1; if (!isReal) { t0 = double.Parse(txtT0.Text); t1 = double.Parse(txtT1.Text); } else { t0 = 0; t1 = ASignal.Count*0.01; } var rk1 = new RKVectorForm(tw1, cn, t0, t1, startVector); RKResults res1 = rk1.SolveWithConstH(res.Count - 1, RKMetodType.RK2_1); functional = GetDiff(res, res1); sb.Append(string.Format("f={0:f6}", functional)); //rtb.Text = sb.ToString(); //this.SetControlFeathe(rtb, "text=", sb.ToString()); output.WriteLine(sb.ToString()); int nn = setCount == 1 ? 1 : 2; for (int i = 0; i < res1.Count - nn; i++) { if (nn == 1) { curves[cn].Add(res1[i].X, res1[i].Y[0]); } else { curves[cn].Add(res1[i].Y[0], res1[i].Y[1]); curves[cn + cnsuff].Add(res1[i].X, res1[i].Y[0]); } } SetControlProperty(zgcMainChart2, "chart", null); //this.zgcMainChart2.AxisChange(); //this.zgcMainChart2.Refresh(); return res1; }
private void btnTransfer_Click(object sender, EventArgs e) { isReal = true; view.Output.ClearScreen(); grcTabRes.DataSource = null; n = int.Parse(txtN.Text); setCount = rbN1.Checked ? 1 : 2; double t = 0; var r = new RKResults(); foreach (double y in ASignal) { r.Add(new RKResult(t, new Vector(1, y))); t += 0.01; } res = r; randomStartParameters = GetRandomStartParam(); var gammaList = new List<double>(); for (int i = 0; i < dgvGama.ColumnCount; i++) { gammaList.Add(Convert.ToDouble(dgvGama.Rows[0].Cells[i].Value)); } var list = new List<TaskParameter>(); for (int i = 0; i < dgvParameters.RowCount; i++) { var tp = new TaskParameter(dgvParameters.ColumnCount); for (int j = 0; j < dgvParameters.ColumnCount; j++) { double val = Convert.ToDouble(dgvParameters.Rows[i].Cells[j].Value); tp.Param[j] = val; } list.Add(tp); } tps = new TaskParameters(list, gammaList); string mfName = setCount == 1 ? "MF1" : "MF2"; funcDescr = new Functions_2_2(mfName, fnames[(sfList.SelectedItem as string).ToUpper()]); startVector = new Vector(1, 0); tw = new TaskWorker(tps, funcDescr.GetType(), funcDescr.MainFuncName, funcDescr.SecFuncName, funcDescr); xtcMain.SelectedTabPageIndex = 2; }
private void btnSolveRK_Click(object sender, EventArgs e) { try { btnSolveRK.Enabled = false; isReal = false; view.Output.ClearScreen(); grcTabRes.DataSource = null; n = int.Parse(txtN.Text, enUsCulture); setCount = rbN1.Checked ? 1 : 2; //this.gamma = double.Parse(txtGamma.Text); if (setCount == 1) { view.ConfigGraphPane(zgcMainChart2, this, PaneLayout.SingleColumn, new List<ChartInfo> { new ChartInfo { Title = "(t,z1)", XAxisTitle = "t", YAxisTitle = "z1" }, }); } else { view.ConfigGraphPane(zgcMainChart2, this, PaneLayout.SingleColumn, new List<ChartInfo> { new ChartInfo { Title = "(t,z1)", XAxisTitle = "t", YAxisTitle = "z1" }, new ChartInfo { Title = "(z1,z2)", XAxisTitle = "z1", YAxisTitle = "z2" } }); } //ZedGraph.GraphPane gp = this.zgcMainChart2.GraphPane; //gp.CurveList.Clear(); curves.Clear(); if (setCount == 1) { curves.Add(curveName, new PointPairList()); zgcMainChart2.MasterPane[0].AddCurve(curveName, curves[curveName], Color.Black, SymbolType.None); } else { curves.Add(curveName, new PointPairList()); curves.Add(curveName + curveNameSuff, new PointPairList()); zgcMainChart2.MasterPane[0].AddCurve(curveName + curveNameSuff, curves[curveName + curveNameSuff], Color.Black, SymbolType.None); zgcMainChart2.MasterPane[1].AddCurve(curveName, curves[curveName], Color.Black, SymbolType.None); } var p = new List<double>(); var gammaList = new List<double>(); for (int i = 0; i < dgvGama.ColumnCount; i++) { double d = double.Parse(dgvGama.Rows[0].Cells[i].Value.ToString().Replace(',', '.'), enUsCulture); gammaList.Add(d); } var list = new List<TaskParameter>(); for (int i = 0; i < dgvParameters.RowCount; i++) { var tp = new TaskParameter(dgvParameters.ColumnCount); for (int j = 0; j < dgvParameters.ColumnCount; j++) { double val = double.Parse(dgvParameters.Rows[i].Cells[j].Value.ToString().Replace(',', '.'), enUsCulture); tp.Param[j] = val; } list.Add(tp); } tps = new TaskParameters(list, gammaList); string mfName = setCount == 1 ? "MF1" : "MF2"; funcDescr = new Functions_2_2(mfName, fnames[(sfList.SelectedItem as string).ToUpper()]); tw = new TaskWorker(tps, funcDescr.GetType(), funcDescr.MainFuncName, funcDescr.SecFuncName, funcDescr); startVector = setCount == 1 ? new Vector(1, double.Parse(txtY0.Text.Replace(',', '.'), enUsCulture)) : new Vector(2, double.Parse(txtY00.Text.Replace(',', '.'), enUsCulture), double.Parse(txtY01.Text.Replace(',', '.'), enUsCulture)); var rk = new RKVectorForm(tw, curveName, double.Parse(txtT0.Text.Replace(',', '.'), enUsCulture), double.Parse(txtT1.Text.Replace(',', '.'), enUsCulture), startVector); res = rk.SolveWithConstH(n, RKMetodType.RK4_1); if (rbN1.Checked) { for (int i = 0; i < res.Count - 1; i++) { curves[curveName].Add(res[i].X, res[i].Y[0]); } //res.ForEach(r => this.curves[curveName].Add(r.X, r.Y[0])); } else { for (int i = 0; i < res.Count - 2; i++) { curves[curveName + curveNameSuff].Add(res[i].X, res[i].Y[0]); curves[curveName].Add(res[i].Y[0], res[i].Y[1]); } //res.ForEach(r => this.curves[curveName].Add(r.Y[0], r.Y[1])); } zgcMainChart2.AxisChange(); zgcMainChart2.Refresh(); if (setCount == 1) { tblResList = new List<ResPointViewType1>(); for (int i = 0; i < res.Count - 1; i++) (tblResList as List<ResPointViewType1>).Add(new ResPointViewType1(res[i].X, res[i].Y[0], -1, -1)); grcTabRes.DataSource = null; grcTabRes.DataSource = tblResList; } else { tblResList = new List<ResPointViewType2>(); for (int i = 0; i < res.Count - 2; i++) (tblResList as List<ResPointViewType2>).Add(new ResPointViewType2(res[i].X, res[i].Y[0], res[i].Y[1], -1, -1)); grcTabRes.DataSource = null; grcTabRes.DataSource = tblResList; } grcTabRes.RefreshDataSource(); } finally { btnSolveRK.Enabled = true; } }