1
votes

Thanks much for your time and for all your help. Actually, I made a mistake in the previous post when specifying the problem. Thus, I reformulate my question using a simpler example. I need to solve symbolically the equation Ct = Z/(P-I) or Ct*(P-I) = Z.

I already know the answer => Ct = [sigma, 1-sigma]

How to program "correctly" the code in order to get the solution

syms sigma;
Ct = sym('Ct',[1 2]);
%    
P = [sigma  1-sigma;
     sigma  1-sigma];
I = [1 0;
     0 1];
Z = [0 0];
%    
solve(Ct*(P-I) == Z);

So far, I get :

Z =

0 0

Warning: The solutions are parametrized by the symbols: z = C_

In solve at 190 In test_matrix_sigma at 13

Or with

  solve(Ct == Z/(P-I), Ct);

I get:

Warning: System is rank deficient. Solution is not unique. Warning: 4 equations in 2 variables.

In /opt/MATLAB/R2013a/toolbox/symbolic/symbolic/symengine.p>symengine at 56 In mupadengine.mupadengine>mupadengine.evalin at 97 In mupadengine.mupadengine>mupadengine.feval at 150 In solve at 170 In test_matrix_sigma at 13

 ---------------------------------------------------------------------------------------

Thanks for the answer !

Now I have two issues: 1) When I try to handla a more complicated system:

syms a b P1 P2;
I = [1 0 0 0;
     0 1 0 0;
     0 0 1 0;
     0 0 0 1]; 
%    
P = [a*P1     (1-a)*P1     (1-b)*(1-P1)  b*(1-P1);    
     a*P1     (1-a)*P1     (1-b)*(1-P1)  b*(1-P1);    
     b*(1-P2) (1-b)*(1-P2) (1-b)*P2      b*(1-P2);    
     b*(1-P2) (1-b)*(1-P2) (1-b)*P2      b*(1-P2)];    
%    
assume(a, 'real'); 
assume(b, 'real'); 
assume(P1, 'real'); 
assume(P2, 'real');
%
answer = null((P-I)');
disp(answer);

I get

ans =

[ empty sym ]

as the only answer.

2) If there is a way in maltlab to "solve" the above symbolic matrix P and find the symbolic determinant ?

For instance, if I do eid(P) it works;

when I do det(P) it gives 0 as answer...

2

2 Answers

2
votes

This post is an answer to a different problem, that was first asked by the OP before being edited. I leave the problem and solution here in case someone ever runs into the same problem:


I need to solve symbolically the following matrix equation to find out Ct (a vector ???):

syms a b P1 P2    
%    
P = [a*P1     (1-a)*P1     (1-b)*(1-P1)  b*(1-P1);    
     a*P1     (1-a)*P1     (1-b)*(1-P1)  b*(1-P1);    
     b*(1-P2) (1-b)*(1-P2) (1-b)*P2      b*(1-P2);    
     b*(1-P2) (1-b)*(1-P2) (1-b)*P2      b*(1-P2)];    
%    
solve(Ct*(P-1) == 0, Ct);

How to proceed ?

So far I get:

Undefined function or variable 'Ct'.

Error in matrix_test (line 10) solve(Ct*(P-1) == 0, Ct);

The error you get is because you did not assign Ct before trying to solve for your equation. In the equation Ct*(P-1) == 0, Matlab does not know what Ct is. You could remedy this by creating a symbolic vector (see sym documentation). For instance:

Ct = sym('Ct', [1 4]);

However, using solve on this would not give you the solutions you're looking for: instead, Matlab is going to give you the trivial answer Ct = 0, which of course is a correct answer to your equation.

What you really want to find is the null space of the (P-1)' matrix: the null space is the set of vectors X such that (P-1)'X = 0 (Which is the same thing as X'(P-1) = 0, so Ct = X'). The Matlab function null (see doc) is what you need. Using your code, I get:

null((P-1)')

ans =

[ -1,  0]
[  1,  0]
[  0, -1]
[  0,  1]

This means that any linear combination of the vectors [-1, 1, 0, 0] and [0, 0, -1, 1] belong to the null space of (P-1)', and therefore its transpose is the Ct you were looking for.

N.B.: This result is easily confirmed by observation of your initial matrix P.

0
votes

This edited problem is only slightly different from the first one. Once again, you are looking to solve an homogeneous system of linear equations.

The warnings you get simply warn you of that: there are an infinity of solutions ; The first warning tells you that the answer is parameterized by C_ (meaning it's in the complex plane, you could add assume(sigma, 'real') and assume(Ct, 'real') if you wanted, you'd get an answer parameterized by R_.

The solution is to find the null space of the matrix (P-I)', as for the previous problem.

null((P-I)')

ans =

 -sigma/(sigma - 1)
                  1

Now if your vector Z became different from 0, you would need to add the particular solution, that is Z/(P-I). In the present case, it gives:

Z/(P-I)
Warning: System is rank deficient. Solution is not unique. 

ans =

[ 0, 0]

This means that in this case the particular solution is [0 0], and the result of null gives you the homogeneous solution. Remember that the complete solution of a linear system of equations is the sum of the particular solution + a linear combination of the elements of the null space. A way to express this in Matlab could be:

syms lambda real;
sol = Z/(P-I) + lambda * null((P-I)')'
sol =

[ -(lambda*sigma)/(sigma - 1), lambda]