public void PlotFunc(FuncString fs, int decimallength = 6, int points = 100, params double[] xstart) { // if (decimallength==0) { // decimallength=6; // } // if (points==0) { // points=100; // } double xa = xstart[0]; double xb = xstart[1]; double x = xa; FuncFigure ff = new FuncFigure(); MyChart mc = new MyChart(); mc.SetChartArea(); for (int i = 0; i < points; i++) { // fc.DealFuncstring( ((decimal)x).ToString()); // fc.DealFuncstring(x.ToString(("f"+decimallength.ToString()))); double result = uc.GetFuncResult(fs, x.ToString(("f" + decimallength.ToString()))); mc.CreateSeriesData(x, result); x = x + 1.0 * (xb - xa) / points; // Console.WriteLine(i+" X={0}\tY={1}",x.ToString(),fc.GetResult()); } // mc.CreateSeriesDatas(new double[]{1,2,3,4,5,6,7,8},new double[]{1,-1,1,-1,1,-1,1,-1}); mc.SetSeries(); ff.AddChart(mc.GetChart()); ff.ShowDialog(); }
public void PlotFuncParallel(FuncString fs, int decimallength = 6, int points = 100, params double[] xstart) { // if (decimallength==0) { // decimallength=6; // } // if (points==0) { // points=100; // } double xa = xstart[0]; double xb = xstart[1]; double x = xa; MyChart mc = new MyChart(); mc.SetChartArea(); int times = 0; Parallel.For(times, points, (i) => { // fc.DealFuncstring( ((decimal)x).ToString()); // fc.DealFuncstring(x.ToString(("f"+decimallength.ToString()))); //在调用之前就已经把参数代进去了 fs是经过替换得到的 double result = uc.GetFuncResult(fs, x.ToString(("f" + decimallength.ToString()))); mc.CreateSeriesData(x, result); x = x + 1.0 * (xb - xa) / points; }); // mc.CreateSeriesDatas(new double[]{1,2,3,4,5,6,7,8},new double[]{1,-1,1,-1,1,-1,1,-1}); mc.SetSeries(); FuncFigure ff = new FuncFigure(); ff.AddChart(mc.GetChart()); ff.ShowDialog(); }