2010年10月8日 星期五

3X3矩陣運算

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int [,] a = new int[4,4];
            int [,] b = new int[4, 4];
            int [,] c = new int[4, 4];

            a[1, 1]=int.Parse(textBox10.Text);
            a[2, 1] = int.Parse(textBox11.Text);
            a[3, 1] = int.Parse(textBox12.Text);
            a[1, 2] = int.Parse(textBox13.Text);
            a[2, 2] = int.Parse(textBox14.Text);
            a[3, 2] = int.Parse(textBox15.Text);
            a[1, 3] = int.Parse(textBox16.Text);
            a[2, 3] = int.Parse(textBox17.Text);
            a[3, 3] = int.Parse(textBox18.Text);

            b[1, 1] = int.Parse(textBox19.Text);
            b[2, 1] = int.Parse(textBox20.Text);
            b[3, 1] = int.Parse(textBox21.Text);
            b[1, 2] = int.Parse(textBox22.Text);
            b[2, 2] = int.Parse(textBox23.Text);
            b[3, 2] = int.Parse(textBox24.Text);
            b[1, 3] = int.Parse(textBox25.Text);
            b[2, 3] = int.Parse(textBox26.Text);
            b[3, 3] = int.Parse(textBox27.Text);
           

            c[1, 1] = a[1, 1] * b[1, 1] + a[1, 2] * b[2, 1] + a[1, 3] * b[3, 1];
            c[1, 2] = a[1, 1] * b[1, 2] + a[1, 2] * b[2, 2] + a[1, 3] * b[3, 2];
            c[1, 3] = a[1, 1] * b[1, 3] + a[1, 2] * b[2, 3] + a[1, 3] * b[3, 3];
            c[2, 1] = a[2, 1] * b[1, 1] + a[2, 2] * b[2, 1] + a[2, 3] * b[3, 1];
            c[2, 2] = a[2, 1] * b[1, 2] + a[2, 2] * b[2, 2] + a[2, 3] * b[3, 2];
            c[2, 3] = a[2, 1] * b[1, 3] + a[2, 2] * b[2, 3] + a[2, 3] * b[3, 3];

            c[3, 1] = a[3, 1] * b[1, 1] + a[3, 2] * b[2, 1] + a[3, 3] * b[3, 1];
            c[3, 2] = a[3, 1] * b[1, 2] + a[3, 2] * b[2, 2] + a[3, 3] * b[3, 2];
            c[3, 3] = a[3, 1] * b[1, 3] + a[3, 2] * b[2, 3] + a[3, 3] * b[3, 3];

           textBox1.Text = Convert.ToString(c[1, 1]);
           textBox2.Text = Convert.ToString(c[1, 2]);
           textBox3.Text = Convert.ToString(c[1, 3]);
           textBox4.Text = Convert.ToString(c[2, 1]);
           textBox5.Text = Convert.ToString(c[2, 2]);
           textBox6.Text = Convert.ToString(c[2, 3]);
           textBox7.Text = Convert.ToString(c[3, 1]);
           textBox8.Text = Convert.ToString(c[3, 2]);
           textBox9.Text = Convert.ToString(c[3, 3]);
           

           
        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {
        }
        private void textBox13_TextChanged(object sender, EventArgs e)
        {
        }
        private void textBox10_TextChanged(object sender, EventArgs e)
        {
        }
    }
}

沒有留言:

張貼留言