Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            NR nR = db.NR.Find(id);

            db.NR.Remove(nR);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 public NR ListarNRPorCodigo(string codigo)
 {
     using (var entities = new DB_LaborSafetyEntities())
     {
         NR nr = entities.NR
                 .Where(pes => pes.Codigo == codigo).FirstOrDefault();
         return(nr);
     }
 }
Exemplo n.º 3
0
 public NR ListarNrPorIdString(string id)
 {
     using (var entities = new DB_LaborSafetyEntities())
     {
         NR nr = entities.NR
                 .Where(pes => pes.CodNR.ToString() == id).FirstOrDefault();
         return(nr);
     }
 }
 public ActionResult Edit([Bind(Include = "OBJECTID,Reference_,Prenom,Societe,Qualite,Nature_ter,Zonage,indice_Equ,Voirie,Autres,NR_Id,Etat,SHAPE_STAr,SHAPE_STLe,SHAPE")] NR nR)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nR).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(nR));
 }
Exemplo n.º 5
0
 public override string ToString()
 {
     return(NV.ToString()
            + NR.ToString()
            + NC.ToString()
            + NL.ToString()
            + N_BPT.ToString()
            + N_UPT.ToString()
            + NOA.ToString()
            + NT.ToString()
            + NIOA.ToString()
            + NTR.ToString());
 }
        // GET: NRs1/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NR nR = db.NR.Find(id);

            if (nR == null)
            {
                return(HttpNotFound());
            }
            return(View(nR));
        }
Exemplo n.º 7
0
        private void PrepPreCalc()
        {
            //Pre-calculates the four main vectors based on expint
            expintN    = new double[M + 1];
            expintP    = new double[M + 1];
            expLambdaN = new double[M + 1];
            expLambdaP = new double[M + 1];

            for (int k = 0; k < M + 1; k++)
            {
                expintN[k]    = NR.Expint(1, (k + 1) * deltS * lambda_n);
                expintP[k]    = NR.Expint(1, (k + 1) * deltS * lambda_p);
                expLambdaN[k] = Math.Exp(-lambda_n * (k + 1) * deltS);
                expLambdaP[k] = Math.Exp(-lambda_p * (k + 1) * deltS);
                spotPrice[k]  = Math.Exp(x_index[k]);
            }
        }
Exemplo n.º 8
0
        public static bool FindTwoViewsMatrices(List <PointF> left, List <PointF> right, Matrix K, out Matrix F, out Matrix E, out Matrix R, out Matrix t, out Matrix X)
        {
            var lps_n = new List <PointF>(left);
            var rps_n = new List <PointF>(right);

            NormalizePoints2d(lps_n, out var NL);
            NormalizePoints2d(rps_n, out var NR);

            F = ComputeMatrix.F(new VectorOfPointF(lps_n.ToArray()), new VectorOfPointF(rps_n.ToArray()));
            if (F == null)
            {
                E = R = t = X = null;
                return(false);
            }
            F = NR.T().Multiply(F).Multiply(NL);
            E = ComputeMatrix.E(F, K);

            DecomposeToRTAndTriangulate(left, right, K, E, out R, out t, out X);

            return(true);
        }
        public void EditarNrInventarioAmbiente(long idInventario, long idNr)
        {
            using (DB_LaborSafetyEntities entities = new DB_LaborSafetyEntities())
            {
                NR_INVENTARIO_AMBIENTE inventarioAmbienteExistente = entities.NR_INVENTARIO_AMBIENTE.Where(invAmb => invAmb.CodInventarioAmbiente == idInventario).FirstOrDefault();
                NR nrInventarioAmbienteExistente = entities.NR.FirstOrDefault(invAmb => invAmb.CodNR == idNr);

                if (inventarioAmbienteExistente == null)
                {
                    throw new KeyNotFoundException();
                }
                else if (nrInventarioAmbienteExistente == null)
                {
                    throw new KeyNotFoundException();
                }
                else
                {
                    inventarioAmbienteExistente.CodNR = idNr;
                }
                entities.SaveChanges();
            }
        }
Exemplo n.º 10
0
    public static void CreateNewRecruit <NR>() where NR : ScriptableObject
    {
        NR asset = RecruitClass.CreateInstance <NR>();

        string path = AssetDatabase.GetAssetPath(Selection.activeObject);

        if (path == "")
        {
            path = "Assets";
        }
        else if (Path.GetExtension(path) != "")
        {
            path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
        }
        string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(NR).ToString() + ".asset");

        AssetDatabase.CreateAsset(asset, assetPathAndName);

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorUtility.FocusProjectWindow();
        Selection.activeObject = asset;
    }
Exemplo n.º 11
0
        private double vgR(int j, int i)
        {
            //Calculates the R coefficient at each step
            double sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;

            for (int k = 1; k <= j - 1; k++)
            {
                sum1 += (mainGrid[j - k, i] - mainGrid[j, i] - k * (mainGrid[j - k - 1, i] - mainGrid[j - k, i])) * (expintN[k - 1] - expintN[k]);
            }
            for (int k = 1; k <= j - 1; k++)
            {
                sum2 += ((mainGrid[j - k - 1, i] - mainGrid[j - k, i]) / (lambda_n * deltS)) * (expLambdaN[k - 1] - expLambdaN[k]);
            }
            for (int k = 1; k <= M - j - 1; k++)
            {
                sum3 += (mainGrid[j + k, i] - mainGrid[j, i] - k * (mainGrid[j + k + 1, i] - mainGrid[j + k, i])) * (expintP[k - 1] - expintP[k]);
            }
            for (int k = 1; k <= M - j - 1; k++)
            {
                sum4 += ((mainGrid[j + k + 1, i] - mainGrid[j + k, i]) / (lambda_p * deltS)) * (expLambdaP[k - 1] - expLambdaP[k]);
            }

            return(sum1 + sum2 + sum3 + sum4 + (K * NR.Expint(1, j * deltS * lambda_n)) - (spotPrice[j] * NR.Expint(1, j * deltS * (lambda_n + 1))));
        }
Exemplo n.º 12
0
        private double vgH(int l, int j, int i)
        {
            //Calculates the Heaviside term at each step, takes the exercise boundary as input from the x_j function
            double sum1 = 0, sum2 = 0;
            double u1 = r * K - q * spotPrice[j];

            if (l <= j)
            {
                return(0);
            }

            for (int k = l - j; k <= M - j - 1; k++)
            {
                sum1 += (1 / nu) * (mainGrid[j + k, i] - k * (mainGrid[j + k + 1, i] - mainGrid[j + k, i])) * (expintP[k - 1] - expintP[k]);
            }
            for (int k = l - j; k <= M - j - 1; k++)
            {
                sum2 += ((mainGrid[j + k + 1, i] - mainGrid[j + k, i]) / (lambda_p * nu * deltS)) * (expLambdaP[k - 1] - expLambdaP[k]);
            }

            double u2 = (1 / nu) * (K * NR.Expint(1, (l - j) * deltS * lambda_p) - spotPrice[j] * NR.Expint(1, (l - j) * deltS * (lambda_p - 1)));

            return(u1 - sum1 - sum2 + u2);
        }
Exemplo n.º 13
0
        public void BuildGrid()
        {
            //Builds the main grid
            double testXi, xi;
            int    heavySwitch, l;

            double[] A, B, C, rh, sol;

            //Creates the boundary conditions running on the top and bottom of the grid
            for (int i = 0; i <= 1; i++)
            {
                if (u == 1)
                {
                    mainGrid[0, i] = 0.0;
                    mainGrid[M, i] = spotPrice[M] - K;
                }
                else
                {
                    mainGrid[0, i] = K - spotPrice[0];
                    mainGrid[M, i] = 0.0;
                }
            }

            for (int i = N - 1; i >= 0; i--) //This is time step backward recurssion
            {
                A  = new double[M - 1];
                B  = new double[M - 1];
                C  = new double[M - 1];
                rh = new double[M - 1];
                for (int j = 1; j < M; j++) //At each time step, run up the stock axis
                {
                    xi          = x_index[j];
                    Aj          = a - Bn;
                    Bj          = vgB(j);
                    Cj          = a + Bp;
                    fj          = mainGrid[j, 1];
                    Rj          = vgR(j, 1);
                    testXi      = x_j(1);
                    l           = (int)Math.Floor(((testXi - xmin) / deltS));
                    Hj          = vgH(l, j, 1);
                    heavySwitch = xi < testXi ? 1 : 0;

                    if ((j != 1) && (j != M - 1))
                    {
                        rh[j - 1] = fj + ((deltT / nu) * Rj) + (deltT * heavySwitch * Hj);
                        A[j - 1]  = Aj;
                        B[j - 1]  = Bj;
                        C[j - 1]  = -Cj;
                    }
                    else
                    {
                        if (j == 1)
                        {
                            rh[j - 1] = (fj + ((deltT / nu) * Rj) + (deltT * heavySwitch * Hj)) - (Aj * mainGrid[j - 1, 0]);
                            B[j - 1]  = Bj;
                            C[j - 1]  = -Cj;
                        }
                        else if (j == M - 1)
                        {
                            rh[j - 1] = (fj + ((deltT / nu) * Rj) + (deltT * heavySwitch * Hj)) + (Cj * mainGrid[j + 1, 0]);
                            A[j - 1]  = Aj;
                            B[j - 1]  = Bj;
                        }
                    }
                }
                NR.TriDiag(ref A, ref B, ref C, ref rh, out sol);
                for (int n = 1; n < M; n++)
                {
                    //Checks against parity violations
                    if (u == 1)
                    {
                        mainGrid[n, 0] = sol[n - 1];
                    }
                    else
                    {
                        mainGrid[n, 0] = sol[n - 1] < K - spotPrice[n] ? K - spotPrice[n] : sol[n - 1];
                    }
                    //Recopies the current time prices to time+1; this is to save space in memory, because mainGrid is only a Mx2 matrix
                    if (i != 0)
                    {
                        mainGrid[n, 1] = mainGrid[n, 0];
                    }
                }
            }

            //Once everything is finished, loads the option prices from time=0 into a vector and passes it to the cubic spline
            for (int j = 0; j <= M; j++)
            {
                optPrices[j] = mainGrid[j, 0];
            }
            NR.Spline(ref spotPrice, ref optPrices, 1e30, 1e30, out y2);
        }
Exemplo n.º 14
0
        private bool sing;        // Indicates whether A is singular.

        public QRdcmp(MatDoub a)
        {
            n = a.nrows();
            MatDoub qt = new MatDoub(n, n);
            MatDoub r  = new MatDoub(a);

            sing = (false);
            int     i, j, k;
            VecDoub c = new VecDoub(n);
            VecDoub d = new VecDoub(n);
            double  scale, sigma, sum, tau;

            for (k = 0; k < n - 1; k++)
            {
                scale = 0.0;
                for (i = k; i < n; i++)
                {
                    scale = Math.Max(scale, Math.Abs(r[i][k]));
                }
                if (scale == 0.0)
                { // Singular case.
                    sing = true;
                    c[k] = d[k] = 0.0;
                }
                else
                { // Form Qk and Qk A.
                    for (i = k; i < n; i++)
                    {
                        r[i][k] /= scale;
                    }

                    for (sum = 0.0, i = k; i < n; i++)
                    {
                        sum += r[i][k] * r[i][k];
                    }

                    sigma    = NR.SIGN(Math.Sqrt(sum), r[k][k]);
                    r[k][k] += sigma;
                    c[k]     = sigma * r[k][k];
                    d[k]     = -scale * sigma;

                    for (j = k + 1; j < n; j++)
                    {
                        for (sum = 0.0, i = k; i < n; i++)
                        {
                            sum += r[i][k] * r[i][j];
                        }
                        tau = sum / c[k];
                        for (i = k; i < n; i++)
                        {
                            r[i][j] -= tau * r[i][k];
                        }
                    }
                }
            }
            d[n - 1] = r[n - 1][n - 1];
            if (d[n - 1] == 0.0)
            {
                sing = true;
            }

            ///////////////////////////
            for (i = 0; i < n; i++)
            { // Form QT explicitly.
                for (j = 0; j < n; j++)
                {
                    qt[i][j] = 0.0;
                }
                qt[i][i] = 1.0;
            }
            for (k = 0; k < n - 1; k++)
            {
                if (c[k] != 0.0)
                {
                    for (j = 0; j < n; j++)
                    {
                        sum = 0.0;
                        for (i = k; i < n; i++)
                        {
                            sum += r[i][k] * qt[i][j];
                        }
                        sum /= c[k];
                        for (i = k; i < n; i++)
                        {
                            qt[i][j] -= sum * r[i][k];
                        }
                    }
                }
            }
            for (i = 0; i < n; i++)
            { // Form R explicitly.
                r[i][i] = d[i];
                for (j = 0; j < i; j++)
                {
                    r[i][j] = 0.0;
                }
            }
        }
 private void NRMethod_click(object sender, RoutedEventArgs e)
 {
     BisectionMethod_Class.MethodName = "N-R Method";
     NR.Begin();
     this.Frame.Navigate(typeof(BisectionMethod));
 }
Exemplo n.º 16
0
        public ActionResult EditProfile(NR.Models.PersonProfile profile, string RadioGender, HttpPostedFileBase file, double? x, double? y, double? w, double? h)
        {
            Person CU = null;

            profile.Username = profile.Username.ToUpper();
            if (RadioGender == "M") profile.Gender = Gender.Man;
            if (RadioGender == "F") profile.Gender = Gender.Woman;
            if (String.IsNullOrWhiteSpace(profile.Email) & string.IsNullOrWhiteSpace(profile.Mobil) & string.IsNullOrWhiteSpace(profile.Phone)) ModelState.AddModelError("", General.ErrorNoContactInfo);

            if (ModelState.IsValid)
            {
                CU = reposetory.GetPerson(profile.PersonID);
                if (profile.PersonID != CU.PersonID) return RedirectToAction("EditProfile");//TODO: Null check
                if (profile.Username != CU.UserName && !reposetory.IsUserNameUniqe(profile.Username.ToUpper())) ModelState.AddModelError("Username", General.ErrorUsernameNotUnique);

                if (!reposetory.SavePerson(CU)) ModelState.AddModelError("Username", General.ErrorSave);
                ViewBag.FormSucces = true;
            }


            if (file != null && file.ContentLength > 0)
            {
                if (CU == null) CU = reposetory.GetPerson(profile.PersonID);
                if (profile.PersonID != CU.PersonID) return RedirectToAction("EditProfile");

                if (CU.PersonID != Guid.Empty)
                {
                    Image image = Image.FromStream(file.InputStream);
                    if (image.Width > 428 & image.Height > 550)
                    {
                        var fileExt = Path.GetExtension(file.FileName);
                        string ProfilDirSetting = ConfigurationManager.AppSettings["ProfileImage"];
                        if (string.IsNullOrWhiteSpace(ProfilDirSetting)) { throw new ArgumentNullException(); }
                        var path = Server.MapPath(String.Format(ProfilDirSetting, CU.PersonID.ToString()));
                        file.SaveAs(path);
                        ViewBag.CropImage = true;
                        ViewBag.ImageWidth = image.Width;
                        ViewBag.ImageHeigh = image.Height;
                    }
                    else
                    {
                        ModelState.AddModelError("", General.ProfileImageToSmall);
                    }

                }
            }

            if (x != null && y != null && h != null && w != null)
            {
                if (CU == null) CU = reposetory.GetPerson(profile.PersonID);
                if (profile.PersonID != CU.PersonID) return RedirectToAction("EditProfile");

                if (CU.PersonID != Guid.Empty)
                {
                    if (!ModifyImage(Convert.ToInt32(x), Convert.ToInt32(y), Convert.ToInt32(w), Convert.ToInt32(h), CU)) ModelState.AddModelError("", General.ProfileImageCropError);
                }

            }


            return View(profile);
        }
Exemplo n.º 17
0
        public static void gaussj(MatDoub a, MatDoub b)
        {
            // Linear equation solution by Gauss-Jordan elimination,
            // equation (2.1.1) above. The input matrix is a[0..n-1][0..n-1].
            // b[0..n-1][0..m-1] is input containing the m right-hand side vectors.
            // On output, a is replaced by its matrix inverse, and b is replaced by
            // the corresponding set of solution vectors.
            int    i, icol = 0, irow = 0, j, k, l, ll, n = a.nrows(), m = a.ncols();
            double big, dum, pivinv;
            VecInt indxc = new VecInt(n);
            VecInt indxr = new VecInt(n);
            VecInt ipiv  = new VecInt(n); // These integer arrays are used

            // for bookkeeping on the pivoting.
            for (j = 0; j < n; j++)
            {
                ipiv[j] = 0;
            }
            for (i = 0; i < n; i++) // This is the main loop over the columns to
                                    // be
            {
                big = 0.0;          // reduced.
                for (j = 0; j < n; j++)
                {
                    // This is the outer loop of the search for a pivot over the entire matrix!
                    if (ipiv[j] != 1) // element.
                    {
                        for (k = 0; k < n; k++)
                        {
                            if (ipiv[k] == 0)
                            {
                                if (Math.Abs(a[j][k]) >= big)
                                {
                                    big  = Math.Abs(a[j][k]);
                                    irow = j;
                                    icol = k;
                                }
                            }
                        }
                    }
                }
                ++(ipiv[icol]);
                // We now have the pivot element, so we interchange rows, if needed,
                // to put the pivot element on the diagonal. The columns are not
                // physically interchanged, only relabeled: indxc[i], the column of the .iC1/th
                // pivot element, is the .iC1/th column that is reduced, while indxr[i] is
                // the row in which that pivot element was originally located.
                // If indxr[i] indxc[i], there is an implied column interchange.
                // With this form of bookkeeping, the solution bs will end up in the
                // correct order, and the inverse matrix will be scrambled by columns.
                if (irow != icol)
                {
                    for (l = 0; l < n; l++)
                    {
                        NR.SWAP(a, irow, l, icol, l);
                    }
                    for (l = 0; l < m; l++)
                    {
                        NR.SWAP(b, irow, l, icol, l);
                    }
                }
                indxr[i] = irow; // We are now ready to divide the pivot row by the
                // pivot element, located at irow and icol.
                indxc[i] = icol;
                if (a[icol][icol] == 0.0)
                {
                    throw new Exception("gaussj: Singular Matrix");
                }
                pivinv        = 1.0 / a[icol][icol];
                a[icol][icol] = 1.0;
                for (l = 0; l < n; l++)
                {
                    a[icol][l] *= pivinv;
                }
                for (l = 0; l < m; l++)
                {
                    b[icol][l] *= pivinv;
                }
                for (ll = 0; ll < n; ll++)
                {
                    // Next, we reduce the rows...
                    if (ll != icol)
                    { // ...except for the pivot one, of course.
                        dum         = a[ll][icol];
                        a[ll][icol] = 0.0;
                        for (l = 0; l < n; l++)
                        {
                            a[ll][l] -= a[icol][l] * dum;
                        }
                        for (l = 0; l < m; l++)
                        {
                            b[ll][l] -= b[icol][l] * dum;
                        }
                    }
                }
            }
            // This is the end of the main loop over columns of the reduction. It
            // only remains to unscramble the solution in view of the column
            // interchanges. We do this by interchanging pairs of columns in the
            // reverse order that the permutation was built up.
            for (l = n - 1; l >= 0; l--)
            {
                if (indxr[l] != indxc[l])
                {
                    for (k = 0; k < n; k++)
                    {
                        NR.SWAP(a, k, indxr[l], k, indxc[l]);
                    }
                }
            }
        }
Exemplo n.º 18
0
 public byte[] CreateNegativeResponse(UDS callingFunction, NR reason)
 {
     // throw new Exception("debugger please");
     return(new byte[] { 0x7F, (byte)callingFunction, (byte)reason });
 }
Exemplo n.º 19
0
        //void decompose();
        private void decompose()
        {
            bool    flag;
            int     i, its, j, jj, k, nm = int.MinValue;
            int     l = int.MinValue;
            double  anorm, c, f, g, h, s, scale, x, y, z;
            VecDoub rv1 = new VecDoub(n);

            g = scale = anorm = 0.0;
            for (i = 0; i < n; i++)
            {
                l      = i + 2;
                rv1[i] = scale * g;
                g      = s = scale = 0.0;
                if (i < m)
                {
                    for (k = i; k < m; k++)
                    {
                        scale += Math.Abs(u[k][i]);
                    }
                    if (scale != 0.0)
                    {
                        for (k = i; k < m; k++)
                        {
                            u[k][i] /= scale;
                            s       += u[k][i] * u[k][i];
                        }
                        f       = u[i][i];
                        g       = -NR.SIGN(Math.Sqrt(s), f);
                        h       = f * g - s;
                        u[i][i] = f - g;
                        for (j = l - 1; j < n; j++)
                        {
                            for (s = 0.0, k = i; k < m; k++)
                            {
                                s += u[k][i] * u[k][j];
                            }
                            f = s / h;
                            for (k = i; k < m; k++)
                            {
                                u[k][j] += f * u[k][i];
                            }
                        }
                        for (k = i; k < m; k++)
                        {
                            u[k][i] *= scale;
                        }
                    }
                }
                w[i] = scale * g;
                g    = s = scale = 0.0;
                if (i + 1 <= m && i + 1 != n)
                {
                    for (k = l - 1; k < n; k++)
                    {
                        scale += Math.Abs(u[i][k]);
                    }
                    if (scale != 0.0)
                    {
                        for (k = l - 1; k < n; k++)
                        {
                            u[i][k] /= scale;
                            s       += u[i][k] * u[i][k];
                        }
                        f           = u[i][l - 1];
                        g           = -NR.SIGN(Math.Sqrt(s), f);
                        h           = f * g - s;
                        u[i][l - 1] = f - g;
                        for (k = l - 1; k < n; k++)
                        {
                            rv1[k] = u[i][k] / h;
                        }
                        for (j = l - 1; j < m; j++)
                        {
                            for (s = 0.0, k = l - 1; k < n; k++)
                            {
                                s += u[j][k] * u[i][k];
                            }
                            for (k = l - 1; k < n; k++)
                            {
                                u[j][k] += s * rv1[k];
                            }
                        }
                        for (k = l - 1; k < n; k++)
                        {
                            u[i][k] *= scale;
                        }
                    }
                }
                anorm = Math.Max(anorm, (Math.Abs(w[i]) + Math.Abs(rv1[i])));
            }
            for (i = n - 1; i >= 0; i--)
            {
                if (i < n - 1)
                {
                    if (g != 0.0)
                    {
                        for (j = l; j < n; j++)
                        {
                            v[j][i] = (u[i][j] / u[i][l]) / g;
                        }
                        for (j = l; j < n; j++)
                        {
                            for (s = 0.0, k = l; k < n; k++)
                            {
                                s += u[i][k] * v[k][j];
                            }
                            for (k = l; k < n; k++)
                            {
                                v[k][j] += s * v[k][i];
                            }
                        }
                    }
                    for (j = l; j < n; j++)
                    {
                        v[i][j] = v[j][i] = 0.0;
                    }
                }
                v[i][i] = 1.0;
                g       = rv1[i];
                l       = i;
            }
            for (i = Math.Min(m, n) - 1; i >= 0; i--)
            {
                l = i + 1;
                g = w[i];
                for (j = l; j < n; j++)
                {
                    u[i][j] = 0.0;
                }
                if (g != 0.0)
                {
                    g = 1.0 / g;
                    for (j = l; j < n; j++)
                    {
                        for (s = 0.0, k = l; k < m; k++)
                        {
                            s += u[k][i] * u[k][j];
                        }
                        f = (s / u[i][i]) * g;
                        for (k = i; k < m; k++)
                        {
                            u[k][j] += f * u[k][i];
                        }
                    }
                    for (j = i; j < m; j++)
                    {
                        u[j][i] *= g;
                    }
                }
                else
                {
                    for (j = i; j < m; j++)
                    {
                        u[j][i] = 0.0;
                    }
                }
                ++u[i][i];
            }
            for (k = n - 1; k >= 0; k--)
            {
                for (its = 0; its < 30; its++)
                {
                    flag = true;
                    for (l = k; l >= 0; l--)
                    {
                        nm = l - 1;
                        if (l == 0 || Math.Abs(rv1[l]) <= eps * anorm)
                        {
                            flag = false;
                            break;
                        }
                        if (Math.Abs(w[nm]) <= eps * anorm)
                        {
                            break;
                        }
                    }
                    if (flag)
                    {
                        c = 0.0;
                        s = 1.0;
                        for (i = l; i < k + 1; i++)
                        {
                            f      = s * rv1[i];
                            rv1[i] = c * rv1[i];
                            if (Math.Abs(f) <= eps * anorm)
                            {
                                break;
                            }
                            g    = w[i];
                            h    = pythag(f, g);
                            w[i] = h;
                            h    = 1.0 / h;
                            c    = g * h;
                            s    = -f * h;
                            for (j = 0; j < m; j++)
                            {
                                y        = u[j][nm];
                                z        = u[j][i];
                                u[j][nm] = y * c + z * s;
                                u[j][i]  = z * c - y * s;
                            }
                        }
                    }
                    z = w[k];
                    if (l == k)
                    {
                        if (z < 0.0)
                        {
                            w[k] = -z;
                            for (j = 0; j < n; j++)
                            {
                                v[j][k] = -v[j][k];
                            }
                        }
                        break;
                    }
                    if (its == 29)
                    {
                        throw new Exception("no convergence in 30 svdcmp iterations");
                    }
                    x  = w[l];
                    nm = k - 1;
                    y  = w[nm];
                    g  = rv1[nm];
                    h  = rv1[k];
                    f  = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y);
                    g  = pythag(f, 1.0);
                    f  = ((x - z) * (x + z) + h * ((y / (f + NR.SIGN(g, f))) - h)) / x;
                    c  = s = 1.0;
                    for (j = l; j <= nm; j++)
                    {
                        i      = j + 1;
                        g      = rv1[i];
                        y      = w[i];
                        h      = s * g;
                        g      = c * g;
                        z      = pythag(f, h);
                        rv1[j] = z;
                        c      = f / z;
                        s      = h / z;
                        f      = x * c + g * s;
                        g      = g * c - x * s;
                        h      = y * s;
                        y     *= c;
                        for (jj = 0; jj < n; jj++)
                        {
                            x        = v[jj][j];
                            z        = v[jj][i];
                            v[jj][j] = x * c + z * s;
                            v[jj][i] = z * c - x * s;
                        }
                        z    = pythag(f, h);
                        w[j] = z;
                        if (z != 0.0)
                        {
                            z = 1.0 / z;
                            c = f * z;
                            s = h * z;
                        }
                        f = c * g + s * y;
                        x = c * y - s * g;
                        for (jj = 0; jj < m; jj++)
                        {
                            y        = u[jj][j];
                            z        = u[jj][i];
                            u[jj][j] = y * c + z * s;
                            u[jj][i] = z * c - y * s;
                        }
                    }
                    rv1[l] = 0.0;
                    rv1[k] = f;
                    w[k]   = x;
                }
            }
        }
Exemplo n.º 20
0
 //Call this method to actually get an option price for a certain stock level
 public double GetPrice(double Sx)
 {
     return(NR.Splint(ref spotPrice, ref optPrices, ref y2, Sx));
 }