Example #1
0
        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);
        }
Example #2
0
 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;
         }
     }
 }
Example #3
0
        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);
        }
Example #4
0
 public RKResults Trancate(int step)
 {
     if (step == 0)
     {
         return(this);
     }
     if (Count > 1)
     {
         var res = new RKResults();
         int i   = step;
         foreach (RKResult r in this)
         {
             if (i == step)
             {
                 res.Add(r);
                 i--;
             }
             else
             {
                 if (i <= 0)
                 {
                     i = step;
                 }
                 else
                 {
                     i--;
                 }
             }
         }
         return(res);
     }
     else
     {
         throw new ArgumentException();
     }
 }
Example #5
0
 public RAlgSolver(TaskWorker tw, RKResults res, List <List <double> > startParameters, double[] dz)
     : this(tw, res, startParameters)
 {
     this.dz = dz;
 }
Example #6
0
        public RKResults SolveWithConstH(int N, RKMetodType type)
        {
            var res = new RKResults();

            t.Clear();
            z.Clear();
            Func <double, Vector, double, Vector> RKfunc = null;

            switch (type)
            {
            case RKMetodType.RK4_1:
                RKfunc = RK4_1;
                break;

            case RKMetodType.RK4_2:
                RKfunc = RK4_2;
                break;

            case RKMetodType.RK3_1:
                RKfunc = RK3_1;
                break;

            case RKMetodType.RK3_2:
                RKfunc = RK3_2;
                break;

            case RKMetodType.RK2_1:
                RKfunc = RK2_1;
                break;

            case RKMetodType.RK2_2:
                RKfunc = RK2_2;
                break;
            }
            double h = (t1 - t0) / N;

            H = h;
            double x;
            Vector y;

            t.Add(t0);
            z.Add(Y0);
            var r = new RKResult(t0, Y0);

            res.Add(r);
            OnResultGeneratedCall(r);
            for (int i = 0; i < N; i++)
            {
                y = RKfunc(t[i], z[i], h);
                x = t0 + (i + 1) * h;
                t.Add(x);
                z.Add(y);
                r = new RKResult(x, y);
                res.Add(r);
                OnResultGeneratedCall(r);
            }
            if (OnSolvingDone != null)
            {
                OnSolvingDone(res, curveName, fe);
            }
            return(res);
        }