Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equation system solver fails on simple case #550

Open
WhiteBlackGoose opened this issue Dec 12, 2021 · 0 comments
Open

Equation system solver fails on simple case #550

WhiteBlackGoose opened this issue Dec 12, 2021 · 0 comments
Labels
Minor bug Minor bugs that don't affect the overall computations

Comments

@WhiteBlackGoose
Copy link
Member

WhiteBlackGoose commented Dec 12, 2021

Reported by Isopropanol from Discord

The version I use: AngouriMath

Doesn't solve unless some simple conversation happens (see the comments).

using PeterO.Numbers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using AngouriMath;
using AngouriMath.Extensions;
using static System.Console;
using static AngouriMath.MathS;
using static AngouriMathTester.GaussianElimination;

namespace AngouriMathTester
{
    class Program
    {
        static void Main(string[] args)
        {
            #region Gaussian elimination
            /*
            Entity[,] N = new Entity[3, 4]
            {
                { 1, -1, 2, 6},
                { 2, 3, 2, 11},
                { "X", 2, 1, 8}
            }; // returns true with and right results;
            bool resultBool = LinearEquationSolver.Solve(N);

            Entity[,] M = new Entity[25, 26]{
                { 1, 1, 0, 0, 0, 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , "9.80665 * 998.21 * C_1" },                   // "X_2 - 9.80665 * 998.21 * C_1 + X_1",
                { 0, "-C_2 * 0.0001", 0, 0, 0, 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,-1 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                           // "-(X_19) - C_2 * 0.0001 * X_2",
                { -1, 0, 1, -1, 0, 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                                        // "X_3 - X_1 - X_4",
                { 0, 0, 0, 1, 0, 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , "(-80000) * n_1" ,0 ,0 ,0 ,0 ,0 ,0 , "(800000) * n_1 ^ 2" },       // "(-80000) * X_19 * n_1 + X_4 + (-800000) * n_1 ^ 2",
                { 0, 0, 0, 0, -1, "-C_3 * 0.0001" ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                           // "-(X_5) - C_3 * 0.0001 * X_6",
                { 0, 0, 0, 0, 0, 1 ,0 ,0 ,0 ,0 ,"-40743.6654315252" ,0 ,0 ,0 ,0 , -1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                      // "X_6 - X_16 + -40743.6654315252 * X_11",
                { 0, 0, 0, 0, 0, 0 , -1 , "- C_4 * 0.0001" ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                       // "-(X_7) - C_4 * 0.0001 * X_8",
                { 0, 0, 0, 0, 0, 0 , 0 , 1 ,0 ,0 ,"-40743.6654315252" ,0 ,0 ,0 ,0 , -1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                    // "X_8 - X_16 + -40743.6654315252 * X_11",
                { 0, 0, 0, 0, 0, 0 , 0 , 0 ,-1 , "-C_5 * 0.0001",0 ,0 ,0 ,0 ,0 , 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                        // "-(X_9) - C_5 * 0.0001 * X_10",
                { 0, 0, 0, 0, 0, 0 , 0 , 0 , 0 , 1, "-40743.6654315252",0 ,0 ,0 ,0 , -1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                   // "X_10 - X_16 + -40743.6654315252 * X_11",
                { 0, 0, 0, 0, 1, 0 , 1 , 0 , 1 , 0, -1,0 ,0 ,1 ,0 , 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                                     // "X_5 + X_14 + X_7 - X_11 + X_9",
                { 0, 0, 0, 0, 0, 0 , 0 , 0 , 0 , 0, 0, 1, "40743.6654315252",0 ,0 , 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                     // "40743.6654315252 * X_13 + X_12",
                { 0, 0, 0, 0, -1, 0 , 1, 0 , 1, 0, 0, 0, 1, 1 ,0 , 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                                      // "X_13 - X_5 + X_14 + X_7 + X_9",
                { 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, 0, 0, 0, -1, "-C_6 * 0.0001", 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                         // "-(X_14) - C_6 * 0.0001 * X_15",
                { 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, "-40743.6654315252", 0, 0, 0, 1, -1 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                     // "X_15 - X_16 + -40743.6654315252 * X_11",
                { 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, 0, 1, 0, 0, 0, 1, -1, 0,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                                        // "X_12 - X_17 + X_16",
                { 0, 0, -1, 0, 0, 0 , 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,0 ,0 ,0 ,0 ,0 ,0 ,0 , 0 },                                        // "X_18 - X_3 + X_17",
                { 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, "-C_7 * 0.0001", -1,0 ,0 ,0 ,0 ,0 ,0 , 0 },                          // "-(X_19) - C_7 * 0.0001 * X_18",
                { 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0 , -1 ,0 ,0 ,0 , 0 },                                     // "X_19 - X_22 - X_13",
                { 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 , "80000 * n_2",0 ,0 ,0 , "(800000) * n_2 ^ 2"},          // "X_20 + 80000 * X_22 * n_2 + (-800000) * n_2 ^ 2",
                { 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "-C_8 * 0.0001", 1,0 ,0 ,0 , 0 },                           // "X_22 - C_8 * 0.0001 * X_21",
                { 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,"-C_9 * 0.0001" ,0 ,0 , 0 },                           // "X_22 - C_9 * 0.0001 * X_23",
                { 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ,1 ,0 , "9.80665 * 998.21 * C_1" },                // "X_23 - 9.80665 * 998.21 * C_1 + X_24",
                { 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0 ,-1 ,1, 0 },                                       // "X_25 - X_24 - X_20",
                { 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0 ,0 ,-1, 0 },                                        // "X_21 - X_25 + X_17",
            };
            resultBool = LinearEquationSolver.Solve(M);
            */
            #endregion

            #region AngouriMath
            var system_1 = Equations(
                            "X_8 - v_1 * 0.000100000000000000004792173602385929598312941379845142364501953125 * X_1",
                            "-X_2 - v_2 * 0.000100000000000000004792173602385929598312941379845142364501953125 * X_6",
                            "-X_3 - v_3 * 0.000100000000000000004792173602385929598312941379845142364501953125 * X_4",
                            "X_4 - X_6 + (-40743.6654315252017113380134105682373046875) * X_3",
                            "-X_5 - v_4 * 0.000100000000000000004792173602385929598312941379845142364501953125 * X_6",
                            "X_7 - X_6 + X_1",
                            "X_8 - v_5 * 0.000100000000000000004792173602385929598312941379845142364501953125 * X_7",
                            "X_8 - X_3 - X_9 - X_2",
                            "X_9 - X_12 - X_5",
                            "X_6 - X_10 - X_11",
                            "X_11 + 80000 * X_12 * n + (-800000) * n * n",
                            "X_12- v_6 * 0.000100000000000000004792173602385929598312941379845142364501953125 * X_13",
                            "X_13 - 9789.0960964999997808359069040306866750797257845497032630044387246925907675176858901977539062500000017547 * v_7 + X_10");

            // returns right solution
            var result_1 = system_1.Solve("X_1", "X_2", "X_3", "X_4", "X_5", "X_6", "X_7", "X_8", "X_9", "X_10",
                                      "X_11", "X_12", "X_13");


            Entity y_1 = "-Y_3 - v_3 * 0.000100000000000000004792173602385929598312941379845142364501953125 * Y_4";
            Entity y_2 = "-Y_8 - v_1 * 0.000100000000000000004792173602385929598312941379845142364501953125 * Y_1";
            Entity y_3 = "-Y_8 - v_5 * 0.000100000000000000004792173602385929598312941379845142364501953125 * Y_7";
            Entity y_4 = "Y_7 - Y_6 + Y_1";
            Entity y_5 = "-Y_2 - v_2 * 0.000100000000000000004792173602385929598312941379845142364501953125 * Y_6";
            Entity y_6 = "-Y_5 - v_4 * 0.000100000000000000004792173602385929598312941379845142364501953125 * Y_6";
            Entity y_7 = "Y_4 - Y_6 + (-40743.6654315252017113380134105682373046875) * Y_3";
            Entity y_8 = "Y_9 - Y_3 + Y_2 - Y_8";
            Entity y_9 = "-(Y_5 + Y_12 + Y_9)"; // -Y_9 - Y_5 - Y_12 != -(Y_5 + Y_12 + Y_9)
            Entity y_10 = "Y_6 - Y_10 - Y_11";
            Entity y_11 = "Y_11 + 80000 * Y_12 * n + (-800000) * n * n";
            Entity y_12 = "Y_12 - v_6 * 0.000100000000000000004792173602385929598312941379845142364501953125 * Y_13";
            Entity y_13 = "Y_13 - 9789.0960964999997808359069040306866750797257845497032630044387246925907675176858901977539062500000017547 * v_7 + Y_10";

            var _ = y_9.Simplify();

            var system_2 = Equations(
                            y_1, y_2, y_3, y_4, y_5, y_6, y_7, y_8, y_9, y_10, y_11, y_12, y_13);

            // returns null
            var result_2 = system_2.Solve("Y_4", "Y_1", "Y_8", "Y_7", "Y_2", "Y_5", "Y_6", "Y_3", "Y_9", "Y_10",
                                      "Y_11", "Y_12", "Y_13");


            y_9 = "-Y_9 - Y_5 - Y_12"; // -Y_9 - Y_5 - Y_12 != -(Y_5 + Y_12 + Y_9)
            var system_3 = Equations(
                            y_2, y_5, y_1, y_7, y_6, y_4, y_3, y_8, y_9, y_10, y_11, y_12, y_13);

            // returns right solution
            var result_3 = system_3.Solve("Y_1", "Y_2", "Y_3", "Y_4", "Y_5", "Y_6", "Y_7", "Y_8", "Y_9", "Y_10",
                                      "Y_11", "Y_12", "Y_13");
            #endregion
            Console.Read();
        }
    }
}
@WhiteBlackGoose WhiteBlackGoose added the Minor bug Minor bugs that don't affect the overall computations label Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor bug Minor bugs that don't affect the overall computations
Projects
None yet
Development

No branches or pull requests

1 participant