# Solving a system of Linear Equations with constraints. Using Symbolic math.

4 views (last 30 days)
atharva aalok on 13 Nov 2021
Answered: Tanmay Das on 30 Dec 2021
I have the following system of equations with a constraint:
n equations with n unknowns  Here are all known. (Its a known n*n matrix of values).
The following is my try at a solution. How can I correct it to get the 's
p_ij = [0.5, 0.5; 0.2, 0.8];
length_pi_i = size(p_ij);
length_pi_i = length_pi_i(1);
syms pi [1 length(p_ij)]
assume(sum(pi) == 1);
zero_vector = zeros(length(pi), 1);
eqn = (pi' - (pi * p_ij)' == zero_vector);
M = solve(eqn, pi);
disp(M);

Tanmay Das on 30 Dec 2021
Hi,
I tried reproducing your steps in MATLAB R2021b release and received the following output in the command window:
pi1: 2/7
pi2: 5/7
I tried verifying the answer manually and the answer seems correct to me.
In case you want to learn more about symbolic functions, you may look into 'syms','assume', and 'solve' function documentation.

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!