C# Three-Dimensional Cartesian Vector Calculator (c) September 24, 2023, by James Pate Williams, Jr. All Applicable Rights Reserved

I wrote and debugged this C# code after I found out that my 1989 vector calculator in Modula-2 for the Commadore Amiga 2000 was not working correctly.

// C# Three-Dimensional Cartesian Vector Calculator
// (c) September 24, 2023 by James Pate Williams, Jr.
// All Applicable Rights Reserved

using System;
using System.Windows.Forms;

namespace CSVectorCalculator
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private static double[] A = new double[3];
        private static double[] B = new double[3];
        private static double[] C = new double[3];

        private void ValidateAB(
            ref bool valid)
        {
            try
            {
                A[0] = double.Parse(textBox1.Text);
                A[1] = double.Parse(textBox2.Text);
                A[2] = double.Parse(textBox3.Text);
                B[0] = double.Parse(textBox4.Text);
                B[1] = double.Parse(textBox5.Text);
                B[2] = double.Parse(textBox6.Text);
                
                valid = true;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Warning",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                valid = false;
            }
        }

        private void FillC(double[] C)
        {
            textBox7.Text = C[0].ToString();
            textBox8.Text = C[1].ToString();
            textBox9.Text = C[2].ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool valid = true;

            ValidateAB(ref valid);

            if (valid)
            {
                C[0] = A[0] + B[0];
                C[1] = A[1] + B[1];
                C[2] = A[2] + B[2];

                FillC(C);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bool valid = true;
            
            ValidateAB(ref valid);

            if (valid)
            {
                C[0] = A[0] - B[0];
                C[1] = A[1] - B[1];
                C[2] = A[2] - B[2];

                FillC(C);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            bool valid = true;

            ValidateAB(ref valid);

            if (valid)
            {
                C[0] = A[1] * B[2] - A[2] * B[1];
                C[1] = A[0] * B[2] - A[2] * B[0];
                C[2] = A[1] * B[0] - A[0] * B[1];

                FillC(C);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            bool valid = true;
 
            ValidateAB(ref valid);

            if (valid)
            {
                C[0] = A[0] * B[0] + A[1] * B[1] + A[2] * B[2];
                C[1] = C[2] = 0.0;

                FillC(C);
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            bool valid = true;

            ValidateAB(ref valid);

            if (valid)
            {
                C[0] = Math.Sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
                C[1] = C[2] = 0.0;

                FillC(C);
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            bool valid = true;

            ValidateAB(ref valid);

            if (valid)
            {
                textBox1.Text = C[0].ToString();
                textBox2.Text = C[1].ToString();
                textBox3.Text = C[2].ToString();

                C[0] = C[1] = C[2] = 0.0;

                FillC(C);
            }
        }
    }
}

Comparison of Linear Systems Applications in C# and C++ by James Pate Williams, Jr.

Back in 2017 I created a C# application that implemented the direct methods: Cholesky decomposition, Gaussian elimination with partial pivoting, LU decomposition, and simple Gaussian elimination. The classical iterative methods Gauss-Seidel, Jacobi, Successive Overrelaxation, and gradient descent were also implemented along with the modern iterative methods: conjugate gradient descent and Modified Richardson’s method. Recently I translated the C# code to C++. I used the following test matrices: Cauchy, Lehmer, Pascal, and other. Below are some results. As is apparent the C++ runtimes are faster than the C# execution times.

Richardson Method Translated from C Source Code to C# by James Pate Williams, Jr.

The Richardson Method is called before eliminating the system of linear equations.

Added elimination results from a vanilla C program and a C# application.

These results are not in total agreement with H. T. Lau’s results.

Finite Difference Method for Solving Second Order Ordinary Differential Equations by James Pate Williams, Jr.

My reference is Numerical Analysis: An Algorithmic Approach 3rd Edition by S. D. Conte and Carl de Boor Chapter 9.1.

My 1988 Commodore Amiga 2000 Is Still Functioning by James Pate Williams, Jr.

On Friday September 8, 2023, I setup my thirty-five-year-old personal computer which is a Commodore Amiga 2000. My father bought the computer for me on Saturday, April 30, 1988. It still works although the Commodore 1084 RGB color display has a non-functional power button. My remedy for the problem was to Scotch tape the power button in the “On” position. I have an Amiga BASIC by Microsoft manual and software, a Modula-2 compiler, Motorola MC68000 macro-assembly language software, and a Pecan UCSD Pascal compiler. The Amiga was the first multimedia personal computer. In May 1988 I created two Amiga BASIC programs: a keyboard emulator and a primitive computer-generated music program that used three types of noise namely Brownian, fractal, and white noise. I used the computer extensively in the years 1988 to 1994. In December 1994 my mother and older sister purchased a mom-and-pop store Microsoft-Intel personal computer.