title: Solve a matricial equation, i.e a system of 16 equations with 16 unknown : Error when call solve function
body: <p>I wonder under which conditions I could have equality between two 4x4 matrices. I build my two matrices from which I would like to get an equality.</p>
  <p>But to get this equality, I have to solve an unknown matrix 4x4 whose terms are present in the two matrices 4x4.</p>
  <p>To show you a practical example, I put below a small Matlab script that tries to follow all the reasoning explained above:</p>
  <pre><code>clear;
  clc;
  
  % Big_1 Fisher : 
  FISH_Big_1_SYM = sym('sp_', [5,5], 'real');
  % Force symmetry for Big_1
  FISH_Big_1_SYM = tril(FISH_Big_1_SYM.') + triu(FISH_Big_1_SYM,1);
  
  % Big_2 Fisher : 
  FISH_Big_2_SYM = sym('sp_', [5,5], 'real');
  % Force symmetry for Big_2
  FISH_Big_2_SYM = tril(FISH_Big_2_SYM.') + triu(FISH_Big_2_SYM,1);
  
  % Jacobian 1 
  J_1_SYM = sym('j_', [5,5], 'real');
  % Jacobian 2 
  J_2_SYM = sym('j_', [5,5], 'real');
  
  % Remove 4th row/column
  J_2_SYM(4,:) = [];
  J_2_SYM(:,4) = [];
  
  %%%%%%%% Method 1 : projection before marginalisation %%%%%%%%%
  
  % Projection
  FISH_proj_1 = J_1_SYM'*FISH_Big_1_SYM*J_1_SYM;
  % Check size : 5x5
  size(FISH_proj_1)
  % Invert Fisher_2
  COV_Big_1_SYM = inv(FISH_Big_1_SYM);
  % Marginalisation
  COV_Big_1_SYM(4,:) = [];
  COV_Big_1_SYM(:,4) = [];
  FISH_Big_1_SYM = inv(COV_Big_1_SYM);
  
  
  %%%%%%%% Method 2 : projection after marginalisation %%%%%%%%%
  % Invert Fisher_2
  COV_Big_2_SYM = inv(FISH_Big_2_SYM);
  % Remove 4th row/column
  COV_Big_2_SYM(4,:) = [];
  COV_Big_2_SYM(:,4) = [];
  % Re-inverse
  FISH_Big_2_SYM_new = inv(COV_Big_2_SYM);
  % Projection 2x2
  FISH_proj_2 = J_2_SYM'*FISH_Big_2_SYM_new*J_2_SYM;
  % Check size : 4x4
  size(FISH_proj_2)
  
  
  % Remove 4th row/column of Fisher matrix method 1
  FISH_proj_1(4,:) = [];
  FISH_proj_1(:,4) = [];
  
  % Test equality between 2 matrices
  isequal(FISH_proj_1,FISH_proj_2);
  
  % Matricial equation to solve
  eqn = FISH_proj_1 == FISH_proj_2;
  
  % Solving : Jacobian 4x4 unknown
  [solx, parameters, conditions] = solve(eqn, J_2_SYM, 'ReturnConditions', true);
  solx
  </code></pre>
  <p>Once I finished to build my 2 matrices <code>FISH_proj_1</code> and <code>FISH_proj_2</code>, I get the error in &quot;solve&quot; function :</p>
  <pre><code>Error using sym/solve (line 279)
  Inconsistent output with 1 variables for input argument with 16 variables.
  
  Error in demo_projection_dev (line 62)
  [solx, parameters, conditions] = solve(eqn, J_2_SYM, 'ReturnConditions', true);
  </code></pre>
  <p>The unknown is a Matrix 4x4 named <code>J_2_SYM</code>.</p>
  <p>How to debug this error with solve function ? Is the syntax right if I put <code>J_2_SYM</code> unknown directly in <code>solve</code> function call ?</p>
  <h2>Edit</h2>
  <p>Here a modified source where I tried to explicitly set a vector of symbolic variables (via symbolical vector <code>A</code>) but still an error remains:</p>
  <pre><code>clear;
  clc;
  
  % Big_1 Fisher : 
  FISH_Big_1_SYM = sym('sp_', [5,5], 'real');
  % Force symmetry for Big_1
  FISH_Big_1_SYM = tril(FISH_Big_1_SYM.') + triu(FISH_Big_1_SYM,1);
  
  % Big_2 Fisher : 
  FISH_Big_2_SYM = sym('sp_', [5,5], 'real');
  % Force symmetry for Big_2
  FISH_Big_2_SYM = tril(FISH_Big_2_SYM.') + triu(FISH_Big_2_SYM,1);
  
  % Jacobian 1 
  J_1_SYM = sym('j_', [5,5], 'real');
  % Jacobian 2 
  J_2_SYM = sym('j_', [5,5], 'real');
  % Flattness for vector unknown
  A = sym('j_', [16], 'real');
  
  % Set 0 to after 3
  for i=1:5
    for j=1:5
      if (i == j)
        J_1_SYM(i,j) = 1;
        J_2_SYM(i,j) = 1;
      elseif (i &gt;= 4 || j &gt;= 4 &amp;&amp; i &lt;= 5 &amp;&amp; j &lt;= 5 )
        J_1_SYM(i,j) = 0;
        J_2_SYM(i,j) = 0;
      end
    end
  end    
  disp('here1');
  J_1_SYM
  
  % Remove 4th row/column
  J_2_SYM(4,:) = [];
  J_2_SYM(:,4) = [];
  
  %%%%%%%% Method 1 : projection before marginalisation %%%%%%%%%
  
  % Projection
  FISH_proj_1 = J_1_SYM'*FISH_Big_1_SYM*J_1_SYM;
  % Invert Fisher_2
  COV_Big_1_SYM = inv(FISH_Big_1_SYM);
  % Marginalisation
  COV_Big_1_SYM(4,:) = [];
  COV_Big_1_SYM(:,4) = [];
  FISH_Big_1_SYM = inv(COV_Big_1_SYM);
  
  
  %%%%%%%% Method 2 : projection after marginalisation %%%%%%%%%
  % Invert Fisher_2
  COV_Big_2_SYM = inv(FISH_Big_2_SYM);
  % Remove 4th row/column
  COV_Big_2_SYM(4,:) = [];
  COV_Big_2_SYM(:,4) = [];
  % Re-inverse
  FISH_Big_2_SYM_new = inv(COV_Big_2_SYM);
  % Projection 2x2
  FISH_proj_2 = J_2_SYM'*FISH_Big_2_SYM_new*J_2_SYM;
  
  
  % Remove 4th row/column of Fisher matrix method 1
  FISH_proj_1(4,:) = [];
  FISH_proj_1(:,4) = [];
  
  % Test equality between 2 matrices
  isequal(FISH_proj_1,FISH_proj_2)
  
  % Check size : 4x4
  size(FISH_proj_1)
  % Check size : 4x4
  size(FISH_proj_2)
  
  % Matricial equation to solve
  eqn = FISH_proj_1 == FISH_proj_2;
  
  
  % Flatten matrix to 1D vetcor
  A=reshape(J_2_SYM,1,[]);
  A
  
  % Solving : sigma_o unknown
  solx = solve(eqn, A);
  </code></pre>
  <p>and the error :</p>
  <pre><code>A =
  
  [ 1, j_2_1, j_3_1, 0, j_1_2, 1, j_3_2, 0, j_1_3, j_2_3, 1, 0, 0, 0, 0, 1]
  
  Error using sym.getEqnsVars&gt;checkVariables (line 92)
  Second argument must be a vector of symbolic variables.
  
  Error in sym.getEqnsVars (line 56)
      checkVariables(vars);
  
  Error in sym/solve&gt;getEqns (line 429)
  [eqns, vars] = sym.getEqnsVars(argv{:});
  
  Error in sym/solve (line 226)
  [eqns,vars,options] = getEqns(varargin{:});
  
  Error in demo_projection (line 88)
  solx = solve(eqn, A);
  </code></pre>
  <p>What can I try next?</p>