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.

Euler’s Method and Runge-Kutta 4 Algorithm for Numerically Solving an Ordinary Differential Equation by James Pate Williams, Jr.

https://math.libretexts.org/Courses/Monroe_Community_College/MTH_225_Differential_Equations/3%3A_Numerical_Methods/3.1%3A_Euler’s_Method

I added the Runge-Kutta 4 algorithm found in Numerical Analysis: An Algorithmic Approach Third Edition by S. D. Conte and Carl de Boor. I also added a multistep method, the Adams-Bashforth Method.

Estimated Babe Ruth 1921 Homerun Parameters by James Pate Williams, Jr.

“Babe Ruth is generally considered the owner of the record for the longest home run in MLB history with a 575-foot bomb launched at Navin Field in Detroit in 1921.” – https://www.msn.com/en-us/sports/mlb/what-is-the-longest-home-run-in-mlb-history/ar-AA1dGwlZ

As you can see, I estimated the pitch velocity at 90 miles per hour and Babe Ruth’s (Sultan of Swing) at 90 miles per hour also. My analytic calculations yield a range of the baseball’s trajectory as about 576 feet.