Solve equation with multiple variables

5 views (last 30 days)
Felix Blank
Felix Blank on 2 Jan 2018
Edited: John D'Errico on 27 Aug 2024
Hello,
a matrix operation gave me the following result:
a = b +c
b = a/3 + (2*d)/3
c = a/3 + (2*d)/3
d = b/4 + c /4
a + b + c + d should be equal to one. How can I solve this for the exakt values of a, b, c and d?
Thank you very much in advance!

Answers (2)

Ayush Modi
Ayush Modi on 27 Aug 2024
Hi Felix,
You can solve a system of equations using "solve" function of MATLAB.
Here is the example code to get you started:
% Step-1: Define the symbolic variables.
syms a b c d
% Step-2: Set up the equations based on the relationships provided.
eq1 = a == b + c;
eq2 = b == a/3 + (2*d)/3;
eq3 = c == a/3 + (2*d)/3;
eq4 = d == b/4 + c/4;
eq5 = a + b + c + d == 1;
% Step-3: Use the "solve" function to find the exact values of the variables.
solutions = solve([eq1, eq2, eq3, eq4, eq5], [a, b, c, d]);
disp(solutions)
a: 4/9 b: 2/9 c: 2/9 d: 1/9
Refer to the following MathWorks documentation for more information on "solve" function:

John D'Errico
John D'Errico on 27 Aug 2024
Edited: John D'Errico on 27 Aug 2024
Let me explain SOME of the the mathematics here.
First, you have 4 equations, in 4 unknowns. Typically, that means there is one unique solution when the system of equations is linear. That is only true if the system is full rank. If the system has less than full rank (here, 4) then there will be infinitely many solutions.
Second, the system is a homogeneous system. The idea is, if we moved ALL of the terms with unknowns in them to the left side, and ALL constant terms to the right side of the equality, then the right hand side would have ALL zeros. That is, there are no constant terms. Do you see that?
Next, you should see that if you substitute all zeros in for the unknowns, the equations are trivially satisfied. You would have 0==0 in each case.
To see what case applies here, we can first express this as a linear algebra problem in a standard form.
syms a b c d
eqn(1) = a == b + c;
eqn(2) = b == a/3 + (2*d)/3;
eqn(3) = c == a/3 + (2*d)/3;
eqn(4) = d == b/4 + c /4;
[A,rhs] = equationsToMatrix(eqn,[a,b,c,d])
A = 
rhs = 
As I said, this is a homogeneous system of equations. We can reconstruct what is equivalent to the original system like this:
A*[a;b;c;d] == rhs
ans = 
And, clearly, if we use [0;0;0;0] as a solution, we do have
A*[0;0;0;0] == 0
ans = 
Next, what matters is, what is the rank of A. As I said before, if the matrix A has full rank, then the only solution possible is the all zero solution.
rank(A)
ans = 3
So A has rank only 3. The completely general solution to the homogeneous system is given by the function null.
Anull = null(A)
Anull = 
That is, the unknowns a,b,c,d are given by the vector:
syms t
abcd = Anull*t
abcd = 
And we can see this is a solution to the problem, if we plug it back into the original equations.
subs(eqn,[a;b;c;d],abcd)
ans = 
All of those equations are valid, for ANY value of t.
You want the particular solution where the sum is 1. So we can arbitrarily choose t = 1/9. That will make the sum equal to 1.
sol = abcd/sum(abcd)
sol = 
sum(sol)
ans = 
1
Could you have done this by simply appending the equation a+b+c+d==1 to the system? Well, yes, in this case, that will work. But that may not be correct for all problems. I can give a several trivial examples where it would fail. But I've already long overspent my time on this problem, and doing so would double the amount of writing I've already invested on what is likely homework.

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!