How to determine arbitrary constants with "Solve?"

  • Context: Mathematica 
  • Thread starter Thread starter aheight
  • Start date Start date
  • Tags Tags
    Constants
Click For Summary

Discussion Overview

The discussion revolves around determining arbitrary constants in a system of linear equations using the "Solve" function in Mathematica. Participants explore methods for identifying which variables can be treated as arbitrary when there are more unknowns than equations, particularly in larger systems. The conversation includes technical approaches, coding strategies, and considerations of linear independence.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant describes a scenario with 36 variables and 30 equations, expressing the need for a method to programmatically identify arbitrary variables.
  • Some participants propose that if the equations are linearly independent, any set of 6 variables should be arbitrary.
  • Another participant notes that using the first six variables resulted in an incomplete solution set, suggesting that they may not be linearly independent.
  • There is a suggestion to cast the problem into matrix form to utilize linear algebra routines, such as CoefficientArray and NullSpace.
  • One participant mentions using the function Complement to find elements that are not in both lists of coefficients and solutions.
  • A later reply discusses the conditions under which a homogeneous system of equations will have infinite solutions, specifically referencing the MatrixRank of the coefficient matrix.
  • Another participant shares an example of using Solve to identify arbitrary variables in a simpler equation, noting that it can return a solution with warnings.

Areas of Agreement / Disagreement

Participants express differing views on the identification of arbitrary variables, with some suggesting linear independence as a criterion while others share experiences of incomplete solutions. The discussion remains unresolved regarding the best approach to programmatically determine arbitrary variables in complex systems.

Contextual Notes

Participants mention limitations related to linear independence and the need for specific coding techniques in Mathematica. There are also references to the challenges of handling larger systems of equations and the implications of matrix rank on the existence of non-trivial solutions.

aheight
Messages
318
Reaction score
108
Hi,

I am using Solve to solve a system of linear equations with more unknowns than equations. For example, I have 36 variables and Solve returns 30 equations. Six of the variables I can assign a value of one. But I can only figure out which ones are arbitrary by manually looking at the equations. In the example below, the subscripts 0, 1,2, 10, 11, and 12 are arbitrary. But I would want to solve larger systems and manually looking for the arbitrary variables is not practical. Just to make the notation clear, the subscripts are 0,1,2,3,4,5,10,11,12,13,14,15,20,21,22,23 24,25 and so on for a total of 36.

Would someone know of a way that I can programatically determine which ones are arbitrary and then assign them for example a value of one and then get the rest of them?

Thanks for reading.

##\left\{\left\{s_3\to -10 s_0-6 s_1-3 s_2,s_4\to 15 s_0+8 s_1+3 s_2,s_5\to -6 s_0-3 s_1-s_2,s_{13}\to -40 s_0-16 s_1-4 s_2-10 s_{10}-6 s_{11}-3 s_{12},s_{14}\to 80 s_0+32 s_1+8 s_2+15 s_{10}+8 s_{11}+3 s_{12},s_{15}\to -40 s_0-16 s_1-4 s_2-6 s_{10}-3 s_{11}-s_{12},s_{20}\to -10 s_0-4 s_{10},s_{21}\to -20 s_0-10 s_1-4 s_{10}-4 s_{11},s_{22}\to -30 s_0-20 s_1-10 s_2-4 s_{10}-4 s_{11}-4 s_{12},s_{23}\to 220 s_0+94 s_1+26 s_2+36 s_{10}+20 s_{11}+8 s_{12},s_{24}\to -160 s_0-64 s_1-16 s_2-24 s_{10}-12 s_{11}-4 s_{12},s_{25}\to 0,s_{30}\to 20 s_0+6 s_{10},s_{31}\to 60 s_0+20 s_1+12 s_{10}+6 s_{11},s_{32}\to 120 s_0+60 s_1+20 s_2+18 s_{10}+12 s_{11}+6 s_{12},s_{33}\to -240 s_0-96 s_1-24 s_2-36 s_{10}-18 s_{11}-6 s_{12},s_{34}\to 0,s_{35}\to 0,s_{40}\to -15 s_0-4 s_{10},s_{41}\to -61 s_0-15 s_1-12 s_{10}-4 s_{11},s_{42}\to -154 s_0-61 s_1-15 s_2-24 s_{10}-12 s_{11}-4 s_{12},s_{43}\to 0,s_{44}\to 0,s_{45}\to 0,s_{50}\to 4 s_0+s_{10},s_{51}\to 16 s_0+4 s_1+3 s_{10}+s_{11},s_{52}\to 40 s_0+16 s_1+4 s_2+6 s_{10}+3 s_{11}+s_{12},s_{53}\to 0,s_{54}\to 0,s_{55}\to 0\right\}\right\}
##

And here is what I get when I assign the arbitrary ones to a value of one:

##\left\{\left\{s_3\to -19,s_4\to 26,s_5\to -10,s_{13}\to -79,s_{14}\to 146,s_{15}\to -70,s_{20}\to -14,s_{21}\to -38,s_{22}\to -72,s_{23}\to 404,s_{24}\to -280,s_{25}\to 0,s_{30}\to 26,s_{31}\to 98,s_{32}\to 236,s_{33}\to -420,s_{34}\to 0,s_{35}\to 0,s_{40}\to -19,s_{41}\to -92,s_{42}\to -270,s_{43}\to 0,s_{44}\to 0,s_{45}\to 0,s_{50}\to 5,s_{51}\to 24,s_{52}\to 70,s_{53}\to 0,s_{54}\to 0,s_{55}\to 0\right\}\right\}
##
 
Physics news on Phys.org
Assuming the equations are linearly independent, then any set of 6 should be arbitrary.
 
Dale said:
Assuming the equations are linearly independent, then any set of 6 should be arbitrary.

Hi Dale,

I tried using the first six, s0 through s5 but they must not be linearly independent then because Mathematica then returns an incomplete solution set (containing some s_i's). I have been working on the problem and have reduced it to coding in Mathematica, selecting from two lists, those elements that are not in both lists. This code:

val1 = theSolution // Flatten
val2 = Association[val1]
Keys[val2]
Flatten[theCoefficients]
iList = Intersection[Flatten[theCoefficients], Keys[val2]]

returns two lists: all the coefficients, and all the explicit solutions returned by Solve:

##\left\{s_0,s_1,s_2,s_3,s_4,s_5,s_{10},s_{11},s_{12},s_{13},s_{14},s_{15},s_{20},s_{21},s_{22},s_{23},s_{24},s_{25},s_{30},s_{31},s_{32},s_{33},s_{34},s_{35},s_{40},s_{41},s_{42},s_{43},s_{44},s_{45},s_{50},s_{51},s_{52},s_{53},s_{54},s_{55}\right\} ##

##\left\{s_3,s_4,s_5,s_{13},s_{14},s_{15},s_{20},s_{21},s_{22},s_{23},s_{24},s_{25},s_{30},s_{31},s_{32},s_{33},s_{34},s_{35},s_{40},s_{41},s_{42},s_{43},s_{44},s_{45},s_{50},s_{51},s_{52},s_{53},s_{54},s_{55}\right\}
##

note the second list is missing s0, s1, s2, s10,s11, and s12. Would you know of a compact way of selecting which elements of the two list are not in both of the list? I suppose I could do this by brute force checking each one (not exactly sure how) but I was just wondering if there is a more rule-oriented way of doing it?
 
Last edited:
aheight said:
Hi Dale,

I tried using the first six, s0 through s5 but they must not be linearly independent then because Mathematica then returns an incomplete solution set (containing some s_i's).
For this type of problem, I would strongly recommend casting it as a matrix so that you can use the many existing linear algebra routines.

You can use CoefficientArray to cast it into matrix form. Then you should look at functions like NullSpace
 
  • Like
Likes   Reactions: aheight
Dale said:
For this type of problem, I would strongly recommend casting it as a matrix so that you can use the many existing linear algebra routines.

You can use CoefficientArray to cast it into matrix form. Then you should look at functions like NullSpace

Yes, of course Dale. I should analyze the problem from the perspective of linear algebra.
 
Last edited:
aheight said:
Would you know of a compact way of selecting which elements of the two list are not in both of the list?
By the way, although I recommend the linear algebra approach, if you ever need to do this the function you want is Complement.
 
  • Like
Likes   Reactions: aheight
Dale said:
By the way, although I recommend the linear algebra approach, if you ever need to do this the function you want is Complement.

Thanks. That does the trick! Also I've made progress since you recommended the linear algebra approach: What I have is a homogeneous system of M equations in N unknowns. That system will have a set of infinite solutions (the kind I'm looking for) only if there exists at most N-1 linearly independent equations and I can easily determine this by using MatrixRank of the coefficient matrix. Here's the code I use:

theNormalForm =
Normal[CoefficientArrays[#, Flatten[theCoefficients]]] & /@
theEquations;
theCMatrix = #[[2]] & /@ theNormalForm;
Print["number of equations", Length[theEquations]];
Print["number of variables: ", Length[Flatten[theCoefficients]]];
Print["Matrix Rank: ", MatrixRank[theCMatrix]];

When the MatrixRank is at most one less than the number of variables, I know I have a good (non-trivial) solution.
 
Last edited by a moderator:
By the way, Solve is often capable of working out which variables can be arbitrary. You can give it something like this

Code:
Solve[a+b+c == 7, {a,b,c}]
It will throw a warning, but it will spit out a solution, probably this one:

Code:
{{a -> 7-b-c}}
Then any variables that remain on the right-hand-side of the list of Rules returned can be considered arbitrary.
 

Similar threads

Replies
5
Views
2K
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
2
Views
2K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
8
Views
5K