1

I have an algorithm to produce an n by n matrix A for any given n. My goal is to find all solutions to the homogeneous system of linear equations Ax=0 using Matlab or Mathematica. I'm trying Matlab first.

Attempt 1: I can't use "linsolve" as A is likely to be singular. I want all the solutions.

Attempt 2: Use solve(eqns, vars, 'ReturnConditions', true). However, how do I turn Ax into equation form? It seems that I need a for loop to put equations into the "eqns", but how can I define symbolic variables x1, x2, ..., xn? I don't know the value of n at first. Here is my psudo-code:

read (n);    
for i=1:n %% i_th equation
       eq=[];
       for j=1:n
         eq=eq+A[i,j]*x[j]; %% keep adding terms
       end
       eq=eq+['==0']; %% add '==0' to make it an equation
       eqns=eqns+eq %% add the ith equation to the equation list
 end
 vars=[];
 for i=1:n 
     vars=vars+x[i];
 end
 solve(eqns, vars, 'ReturnConditions', true)

Can you help making it a real Matlab or Mathematica code?

1 Answer 1

1

Matlab is made for linear algebra, so A*x=0 is an equation with one, many or no vector x as a solution.

The problem with Matlab is, it has a great many ways to give you one solution but not to give all solutions. The solution to the linear system Ax=b is usually obtained with x = b\A (where x will have the smallest L0 norm among all solutions, i.e. the fewest non-zero components) or x=pinv(A)*b (where x will have the smallest L2 norm among all solutions). See pinv documentation.

But in this specific case where b=0 , both will give the trivial solution x=0

Now, seeking values of x such that A*x=0 is nothing but looking for the kernel of matrix A. And Matlab null function that does just that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.