示例#1
0
        static public double[] mulscSimSup(matp m, double[] x)
        {
            if (m.n != x.Length)
            {
                MessageBox.Show("Invalid length !");            //i=0 sumt=00*0+01*1+02*2
            }
            double[] rez  = new double[m.n];                    //i=1 sumt=01*0+11*1+12*2
            double   sumt = 0;
            int      d    = 0;

            for (int i = 0; i < m.n; i++)
            {
                for (int j = 0; j < m.n; j++)
                {
                    if (j >= d)
                    {
                        sumt += (m.m[i, j] * x[j]);
                    }
                    else
                    {
                        sumt += (m.m[j, i] * x[j]);
                    }
                }
                rez[i] = sumt;
                sumt   = 0;
                d++;
            }

            return(rez);
        }
示例#2
0
        private double[] getSolDiag(matp Diag, double[] b)
        {
            if (Diag.n != b.Length)
            {
                MessageBox.Show("Invalid Length !");
            }
            double[] x = new double[Diag.n];

            for (int i = 0; i < n; i++)
            {
                x[i] = b[i] / Diag.m[i, i];
            }
            return(x);
        }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            A = new matp(textA.Text);
            n = A.n;
            //D = new matp(n);
            D = new double[n];
            //L = new matp(n);
            //LT = new matp(n);

            b = getB(textb.Text);

            for (int i = 0; i < n; i++)
            {
                //L.m[i,i]=1;
                //LT.m[i,i]=1;
            }
            for (int p = 0; p < n; p++)
            {
                doPas(p);
            }
            int t = Convert.ToInt32(texteps.Text);

            eps = Math.Pow(10, -t);

            afisDesc();

            double detd = 1;

            foreach (var it in D)
            {
                detd *= it;
            }

            textshow.Clear();
            textshow.AppendText("Det A=" + A.detSimSup() + Environment.NewLine);
            textshow.AppendText("Det L=" + 1 + "\tDet D=" + detd + "\tDet LT=" + 1 + Environment.NewLine);
            //textshow.AppendText("Det L=" + L.det() + "\tDet D=" + D.det() + "\tDet LT=" + LT.det()+Environment.NewLine);

            double[] z = getSolTinf(A, b);
            double[] y = getSolDiag2(D, z);
            double[] x = getSolTsup2(A, y);
            foreach (var it in x)
            {
                textshow.AppendText(it + "  \t");
            }

            MessageBox.Show("Solution is: " + testChol(x).ToString());
        }
示例#4
0
        public matp[] section()
        {
            matp[] blocs = new matp[4];
            for (int i = 0; i < 4; i++)
                blocs[i] = new matp(this.n / 2);

            for (int i = 0; i < n / 2; i++)
                for (int j = 0; j < n / 2; j++)
                {
                    blocs[0].m[i, j] = this.m[i, j];
                    blocs[1].m[i, j] = this.m[i, j + n / 2];
                    blocs[2].m[i, j] = this.m[i + n / 2, j];
                    blocs[3].m[i, j] = this.m[i + n / 2, j + n / 2];
                }

            return blocs;
        }
示例#5
0
        static public matp remake(matp[] ms)
        {
            int  n  = ms[0].n * 2;
            matp mr = new matp(n);

            for (int i = 0; i < n / 2; i++)
            {
                for (int j = 0; j < n / 2; j++)
                {
                    mr.m[i, j]                 = ms[0].m[i, j];
                    mr.m[i, j + n / 2]         = ms[1].m[i, j];
                    mr.m[i + n / 2, j]         = ms[2].m[i, j];
                    mr.m[i + n / 2, j + n / 2] = ms[3].m[i, j];
                }
            }
            return(mr);
        }
示例#6
0
        private void button1_Click(object sender, EventArgs e)
        {
            A  = new matp(textA.Text);
            n  = A.n;
            D  = new matp(n);
            L  = new matp(n);
            LT = new matp(n);

            b = getB(textb.Text);

            for (int i = 0; i < n; i++)
            {
                L.m[i, i]  = 1;
                LT.m[i, i] = 1;
            }
            for (int p = 0; p < n; p++)
            {
                doPas(p);
            }
            int t = Convert.ToInt32(texteps.Text);

            eps = Math.Pow(10, -t);

            textL.Clear();
            textL.AppendText(L.ToString());
            textD.Clear();
            textD.AppendText(D.ToString());
            textLT.Clear();
            textLT.AppendText(LT.ToString());

            textshow.Clear();
            textshow.AppendText("Det A=" + A.det() + Environment.NewLine);
            textshow.AppendText("Det L=" + L.det() + "\tDet D=" + D.det() + "\tDet LT=" + LT.det() + Environment.NewLine);

            double[] z = getSolTinf(L, b);
            double[] y = getSolDiag(D, z);
            double[] x = getSolTsup(LT, y);
            foreach (var it in x)
            {
                textshow.AppendText(it + "  \t");
            }

            MessageBox.Show("Solution is: " + testChol(x).ToString());
        }
示例#7
0
        static public matp sub(matp m1, matp m2)
        {
            if (m1.n != m2.n)
            {
                Console.WriteLine("Wrong sub!");
                return(new matp(1));
            }
            int  n   = m1.n;
            matp rez = new matp(n);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    rez.m[i, j] = m1.m[i, j] - m2.m[i, j];
                }
            }
            return(rez);
        }
示例#8
0
        private void button1_Click(object sender, EventArgs e)
        {
            A = new matp(textA.Text);
            n = A.n;
            //D = new matp(n);
            D = new double[n];
            //L = new matp(n);
            //LT = new matp(n);

            b=getB(textb.Text);

            for(int i=0;i<n;i++)
            {
                //L.m[i,i]=1;
                //LT.m[i,i]=1;
            }
            for (int p = 0; p < n; p++)
                doPas(p);
            int t=Convert.ToInt32(texteps.Text);
            eps = Math.Pow(10, -t);

            afisDesc();

            double detd=1;
            foreach (var it in D)
                detd *= it;

            textshow.Clear();
            textshow.AppendText("Det A=" + A.detSimSup() + Environment.NewLine);
            textshow.AppendText("Det L=" + 1 + "\tDet D=" + detd + "\tDet LT=" + 1 + Environment.NewLine);
            //textshow.AppendText("Det L=" + L.det() + "\tDet D=" + D.det() + "\tDet LT=" + LT.det()+Environment.NewLine);

            double[] z = getSolTinf(A, b);
            double[] y = getSolDiag2(D, z);
            double[] x = getSolTsup2(A, y);
            foreach (var it in x)
                textshow.AppendText(it + "  \t");

            MessageBox.Show("Solution is: "+testChol(x).ToString());               

        }
示例#9
0
        private void button1_Click(object sender, EventArgs e)
        {
            A = new matp(textA.Text);
            n = A.n;
            D = new matp(n);
            L = new matp(n);
            LT = new matp(n);

            b=getB(textb.Text);

            for(int i=0;i<n;i++)
            {
                L.m[i,i]=1;
                LT.m[i,i]=1;
            }
            for (int p = 0; p < n; p++)
                doPas(p);
            int t=Convert.ToInt32(texteps.Text);
            eps = Math.Pow(10, -t);

            textL.Clear();
            textL.AppendText(L.ToString());
            textD.Clear();
            textD.AppendText(D.ToString());
            textLT.Clear();
            textLT.AppendText(LT.ToString());

            textshow.Clear();
            textshow.AppendText("Det A=" + A.det()+Environment.NewLine);
            textshow.AppendText("Det L=" + L.det() + "\tDet D=" + D.det() + "\tDet LT=" + LT.det()+Environment.NewLine);

            double[] z = getSolTinf(L, b);
            double[] y = getSolDiag(D, z);
            double[] x = getSolTsup(LT, y);
            foreach (var it in x)
                textshow.AppendText(it + "  \t");

            MessageBox.Show("Solution is: "+testChol(x).ToString());
                

        }
示例#10
0
        static public double[] mulsc(matp m, double[] x)
        {
            if (m.n != x.Length)
            {
                MessageBox.Show("Invalid length !");
            }
            double[] rez  = new double[m.n];
            double   sumt = 0;

            for (int i = 0; i < m.n; i++)
            {
                for (int j = 0; j < m.n; j++)
                {
                    sumt += (m.m[i, j] * x[j]);
                }
                rez[i] = sumt;
                sumt   = 0;
            }

            return(rez);
        }
示例#11
0
        private double[] getSolDiag(matp Diag, double[] b)
        {
            if (Diag.n != b.Length)
            {
                MessageBox.Show("Invalid Length !");
            }
            double[] x = new double[Diag.n];

            for (int i = 0; i < n; i++)
            {
                if (Math.Abs(Diag.m[i, i]) > eps)
                {
                    x[i] = b[i] / Diag.m[i, i];
                }
                else
                {
                    MessageBox.Show("Divide by 0 !");
                }
            }
            return(x);
        }
示例#12
0
        private double[] getSolTinf(matp Tinf, double[] b)
        {
            if (Tinf.n != b.Length)
            {
                MessageBox.Show("Invalid Length !");
            }
            double[] x   = new double[Tinf.n];
            double   sum = 0;

            x[0] = b[0];
            for (int i = 1; i < n; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    sum += (Tinf.m[i, j] * x[j]);
                }
                x[i] = b[i] - sum;
                sum  = 0;
            }
            return(x);
        }
示例#13
0
        private double[] getSolTsup(matp Tsup, double[] b)
        {
            if (Tsup.n != b.Length)
            {
                MessageBox.Show("Invalid Length !");
            }
            double[] x   = new double[Tsup.n];
            double   sum = 0;

            x[n - 1] = b[n - 1];
            for (int i = n - 2; i >= 0; i--)
            {
                for (int j = i; j < n; j++)
                {
                    sum += (Tsup.m[i, j] * x[j]);
                }
                x[i] = b[i] - sum;
                sum  = 0;
            }
            return(x);
        }
示例#14
0
        public matp[] section()
        {
            matp[] blocs = new matp[4];
            for (int i = 0; i < 4; i++)
            {
                blocs[i] = new matp(this.n / 2);
            }

            for (int i = 0; i < n / 2; i++)
            {
                for (int j = 0; j < n / 2; j++)
                {
                    blocs[0].m[i, j] = this.m[i, j];
                    blocs[1].m[i, j] = this.m[i, j + n / 2];
                    blocs[2].m[i, j] = this.m[i + n / 2, j];
                    blocs[3].m[i, j] = this.m[i + n / 2, j + n / 2];
                }
            }

            return(blocs);
        }
示例#15
0
        static public matp mul(matp m1, matp m2)
        {
            if (m1.n != m2.n)
            {
                Console.WriteLine("Wrong mul!");
                return(new matp(1));
            }

            int  n   = m1.n;
            matp rez = new matp(n);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    for (int k = 0; k < n; k++)
                    {
                        rez.m[i, j] += (m1.m[i, k] * m2.m[k, j]);
                    }
                }
            }
            return(rez);
        }
示例#16
0
        static public matp remake(matp[] ms)
        {
            int n = ms[0].n * 2;
            matp mr = new matp(n);

            for (int i = 0; i < n / 2; i++)
                for (int j = 0; j < n / 2; j++)
                {
                    mr.m[i, j] = ms[0].m[i, j];
                    mr.m[i, j + n / 2] = ms[1].m[i, j];
                    mr.m[i + n / 2, j] = ms[2].m[i, j];
                    mr.m[i + n / 2, j + n / 2] = ms[3].m[i, j];
                }
            return mr;
        }
示例#17
0
        static public matp sub(matp m1, matp m2)
        {
            if (m1.n != m2.n)
            {
                Console.WriteLine("Wrong sub!");
                return new matp(1);
            }
            int n = m1.n;
            matp rez = new matp(n);

            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    rez.m[i, j] = m1.m[i, j] - m2.m[i, j];
            return rez;
        }
示例#18
0
        static public double[] mulscSimSup(matp m, double[] x)
        {
            if (m.n != x.Length)
                MessageBox.Show("Invalid length !");            //i=0 sumt=00*0+01*1+02*2
            double[] rez = new double[m.n];                     //i=1 sumt=01*0+11*1+12*2
            double sumt = 0;
            int d = 0;
            for (int i = 0; i < m.n; i++)
            {
                for (int j = 0; j < m.n; j++)
                    if (j >= d)
                        sumt += (m.m[i, j] * x[j]);
                    else
                        sumt += (m.m[j, i] * x[j]);
                rez[i] = sumt;
                sumt = 0;
                d++;
            }

            return rez;
        }
示例#19
0
        static public double[] mulsc(matp m, double[] x)
        {
            if (m.n != x.Length)
                MessageBox.Show("Invalid length !");
            double[] rez = new double[m.n];
            double sumt = 0;
            for (int i = 0; i < m.n; i++)
            {
                for (int j = 0; j < m.n; j++)
                    sumt += (m.m[i, j] * x[j]);
                rez[i] = sumt;
                sumt = 0;
            }

            return rez;
        }
示例#20
0
        static public matp mul(matp m1, matp m2)
        {
            if (m1.n != m2.n)
            {
                Console.WriteLine("Wrong mul!");
                return new matp(1);
            }

            int n = m1.n;
            matp rez = new matp(n);

            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    for (int k = 0; k < n; k++)
                        rez.m[i, j] += (m1.m[i, k] * m2.m[k, j]);
            return rez;
        }
示例#21
0
        private double[] getSolDiag(matp Diag, double[] b)
        {
            if (Diag.n != b.Length)
                MessageBox.Show("Invalid Length !");
            double[] x = new double[Diag.n];

            for (int i = 0; i < n; i++)
                if(Math.Abs(Diag.m[i,i])>eps)
                    x[i] = b[i] / Diag.m[i, i];
                else
                    MessageBox.Show("Divide by 0 !");
            return x;
        }
示例#22
0
        private double[] getSolTinf(matp Tinf, double[] b)
        {
            if (Tinf.n != b.Length)
                MessageBox.Show("Invalid Length !");
            double[] x = new double[Tinf.n];
            double sum = 0;

            x[0] = b[0];
            for (int i = 1; i < n; i++)
            {
                for (int j = 0; j < i; j++)
                    sum += (Tinf.m[i, j] * x[j]);
                x[i] = b[i] - sum;
                sum = 0;
            }
            return x;
        }
示例#23
0
        private double[] getSolTsup(matp Tsup, double[] b)
        {
            if (Tsup.n != b.Length)
                MessageBox.Show("Invalid Length !");
            double[] x = new double[Tsup.n];
            double sum = 0;

            x[n - 1] = b[n - 1];
            for (int i = n - 2; i >= 0; i--)
            {
                for (int j = i; j < n; j++)
                    sum += (Tsup.m[i, j] * x[j]);
                x[i] = b[i] - sum;
                sum = 0;
            }
            return x;
        }
示例#24
0
        private double[] getSolDiag(matp Diag, double[] b)
        {
            if (Diag.n != b.Length)
                MessageBox.Show("Invalid Length !");
            double[] x = new double[Diag.n];

            for (int i = 0; i < n; i++)
                x[i] = b[i] / Diag.m[i, i];
            return x;
        }