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?