public static Vector operator *(double k, Vector v2) { var resv = new Vector(v2.Count); for (int i = 0; i < resv.Count; i++) resv[i] = k*v2[i]; return resv; }
public static Vector operator +(Vector v1, Vector v2) { var resv = new Vector(v1.Count); for (int i = 0; i < resv.Count; i++) resv[i] = v1[i] + v2[i]; return resv; }
public double FunctionSet(double t, Vector y, int index, TaskParameters tp) { object res = classType.InvokeMember(SecondFunctionName, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Static, null, target, new object[] {t, y, tp[index]}); return (double) res; }
public Vector AbstractFunction(double t, Vector y, TaskParameters tps) { object res = classType.InvokeMember(MainFunctionName, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Static, null, target, new object[] {t, y, tps}); return res as Vector; }
public void SetAlgorithmParameters(double a, double b, Vector Y0) { t0 = a; t1 = b; this.Y0 = Y0; t = new List<double>(); z = new List<Vector>(); N = Y0.Count; }
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; } } }
public static Vector operator /(Vector v1, double d) { var resv = new Vector(v1.Count); for (int i = 0; i < resv.Count; i++) resv[i] = v1[i]/d; return resv; }
private Vector RK4_1(double x, Vector y, double h, int j, TaskParameters taskP) { var res = new Vector(2); Vector f0, f1, f2, f3; f0 = h * ff(x, y, j, taskP); f1 = h * ff(x + h / 2, y + f0 / 2, j, taskP); f2 = h * ff(x + h / 2, y + f1 / 2, j, taskP); f3 = h * ff(x + h, y + f2, j, taskP); res = y + (f0 + 2 * f1 + 2 * f2 + f3) / 6; return res; }
private Vector ff(double t, Vector y, int j, TaskParameters taskP) { return new Vector(2, y[1], tw.FunctionSet(t, y, j, taskP)); }
protected Vector RK2_2(double x, Vector y, double h) { var res = new Vector(N); Vector f0, f1; f0 = h*f(x, y); f1 = h*f(x + h/2, y + f0/2); res = y + f1; return res; }
private double CalcFunct1(TaskParameters taskP) { double f = 0; var val = new List<double>(); var v = new List<Vector>(); double h = res.GetH(); var rk = new Vector[res.Count - 1]; rk[0] = new Vector(1, startP[0]); itab[0] = 1; double t = res[0].X; for (int i = 1; i < res.Count - 1; i++) { val.Clear(); v.Clear(); for (int j = 0; j < tw.SetCount; j++) { double x1 = rk[i - 1][0] + tw.FunctionSet(t, rk[i - 1], j, taskP) * h; v.Add(new Vector(1, x1)); val.Add(Math.Abs(x1 - res[i].Y[0])); } double min = val.Min(); int index = val.IndexOf(min); rk[i] = v[index]; itab[i] = index + 1; f += min * min * h; t = t + h; } return f; }
public RKVectorForm(IFunctionExecuter fe, string curveName, double a, double b, Vector Y0) : this(fe, curveName) { SetAlgorithmParameters(a, b, Y0); }
//public static Vector RKMethod(double x, Vector y, double h,int n,) //{ // Vector r=new Vector //} protected Vector RK4_2(double x, Vector y, double h) { var res = new Vector(N); Vector f0, f1, f2, f3; f0 = h*f(x, y); f1 = h*f(x + h/4, y + f0/4); f2 = h*f(x + h/2, y + f1/2); f3 = h*f(x + h, y + f0 - 2*f1 + 2*f2); res = y + (f0 + 4*f2 + f3)/6; return res; }
protected Vector RK3_2(double x, Vector y, double h) { var res = new Vector(N); Vector f0, f1, f2; f0 = h*f(x, y); f1 = h*f(x + h/3, y + f0/3); f2 = h*f(x + 2*h/3, y + 2*f1/3); res = y + (f0 + 3*f2)/4; return res; }
protected Vector RK3_1(double x, Vector y, double h) { var res = new Vector(N); Vector f0, f1, f2; f0 = h*f(x, y); f1 = h*f(x + h/2, y + f0/2); f2 = h*f(x + h/2, y - f0 + 2*f1); res = y + (f0 + 4*f1 + f2)/6; return res; }
private double CalcFunct2_1(TaskParameters taskP) { double f = 0; var val = new List<double>(); var min1List = new List<double>(); //List<double> min2List = new List<double>(); var v = new List<Vector>(); double h = res.GetH(); var rk = new Vector[res.Count - 1]; rk[0] = new Vector(2, startP[0], startP[1]); itab[0] = 1; double t = res[0].X; for (int i = 1; i < res.Count - 2; i++) { val.Clear(); min1List.Clear(); v.Clear(); for (int j = 0; j < tw.SetCount; j++) { Vector vv = RK4_1(t, rk[i - 1], h, j, taskP); v.Add(vv); double min1 = Math.Abs(vv[0] - res[i].Y[0]); //double min2 = Math.Abs(vv[1] - this.dz[i]); val.Add(min1); min1List.Add(min1); //min2List.Add(min2); //if (i < this.dz.Length) //{ // val2.Add(Math.Abs(vv[1] - this.dz[i])); //} } double min = val.Min(); int index = val.IndexOf(min); rk[i] = v[index]; itab[i] = index + 1; //f += min * min * h; f += (Math.Pow(min1List[index], 2) + alpha * (v[index][0] * v[index][0] + v[index][1] * v[index][1])) * h; t = t + h; } return f; }
protected Vector RK2_1(double x, Vector y, double h) { var res = new Vector(N); Vector f0, f1; f0 = h*f(x, y); f1 = h*f(x + h, y + f0); res = y + (f0 + f1)/2; return res; }