using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            

            double[] a = { 0, 7, 10, 13, 16}; 
            double[] b = { 5, 8, 11, 14, 17};
            double[] c ={ 6, 9, 12, 15, 0 };
            double[] d ={ 5, 8, 5, 2, 4 };

            int N = d.Length;

            double[] Centre = new double[N];
            

           Centre=TDMASolve(a,b,c,d);
           double afar=2/12.0;
        }

        double[] TDMASolve(double[] a, double[] b, double[] c, double[] d)
        {
            /* Warning: will modify c and d! */
            int n = d.Length; /* All arrays should be the same length */
            double[] x = new double[n];
            double id;

            /* Modify the coefficients. */
            c[0] /= b[0]; /* Division by zero risk. */
            d[0] /= b[0]; /* Division by zero would imply a singular matrix. */
            for (int i = 1; i < n; i++)
            {
                id = b[i] - c[i - 1] * a[i];
                c[i] /= id; /* This calculation during the last iteration is redundant. */
                d[i] = (d[i] - d[i - 1] * a[i]) / id;
            }

            /* Now back substitute. */
            x[n - 1] = d[n - 1];
            for (int i = n - 2; i >= 0; i--)
            {
                x[i] = d[i] - c[i] * x[i + 1];
            }

            return x;
        }

    }
}