multiple equations multiple variables solve command does not work

6 views (last 30 days)
Hello, I'm trying to solve a set of equations but i know the unknown variables don't have exact answers, instead i need to find something else:
the variables are b , d , e
the equations are;
eqn1 = ((d-e)/1.8)-(e/3.3)-((e-b)/0.68)== 0
eqn2 = ((e-b)/0.68) == ((b-9)/4.7)+((b+3)/1.5)
eqn3 = ((9-d)/1.5) == ((d)/4.7) + ((d-e)/1.8)
I want to find;
d-e = ?
b isnt required to be known, but i would be happy if you showed me a way to find the answer with learning b and without needing b at all,
The main problem for me here is not to solve this easily, but to understand. I can solve using other internet calcualtors somehow but i want to learn how i can get a wanted value the next time i have x equations and y variables.
Thank you
  1 Comment
Cem Taylan Meriç
Cem Taylan Meriç on 2 Nov 2021
Also when i write all the commands below and write s.e for example it says "unable to resolve the name s.e." so i would be happy if you could explain or correct me this as well.
syms b d e
eqn1 = ((d-e)/1.8)-(e/3.3)-((e-b)/0.68)== 0
eqn2 = ((e-b)/0.68) == ((b-9)/4.7)+((b+3)/1.5)
eqn3 = ((9-d)/1.5) == ((d)/4.7) + ((d-e)/1.8)

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 2 Nov 2021
Edited: John D'Errico on 2 Nov 2021
You asked a very general question at the end, how to solve a problem with a different number of unknowns than equations, and at the same time, to solve for the difference of two of the unknowns. Depending on if the equations are linear or nonlinear, the answer is of course very different. And it will also depend on if there are fewer equations than unknowns or more equations than unknowns. The point is, your question is far too vague for any good complete answer to be offered, at least in less than could be found in a combination of several courses on linear algebra, nonlinear equations, and mathematics in general.
In the problem you show, there are three linear equations, and three unknowns. That means the problem is trivially solvable for all three unknowns, as long as the system of equations has full rank.(As I said, understanding linear algebra is important here.)
syms b d e
eqn(1) = ((d-e)/1.8)-(e/3.3)-((e-b)/0.68)== 0;
eqn(2) = ((e-b)/0.68) == ((b-9)/4.7)+((b+3)/1.5);
eqn(3) = ((9-d)/1.5) == ((d)/4.7) + ((d-e)/1.8);
% we can rewrite this as a linear system of equations.
[A,rhs] = equationsToMatrix(eqn,[b d e])
A = 
rhs = 
The idea is now, we can solve the problem using tools like backslash, but first, it will tell us if the problem is well posed. That is, do we have sufficient information to determine all three constants? Rank will tell us. If the matrix A has full rank, then a unique solution exists for all three constants.
ans = 3
So the matrix A has full rank. It is now simplest to use backslash to solve for the unknowns, but we could also have just used solve. That is:
bde = A\rhs
bde = 
Or, we could do:
[bsol,dsol,esol] = solve(eqn,[b,d,e])
bsol = 
dsol = 
esol = 
If you want the results in a floating point forrm instead of fractions, then use VPA or DOUBLE on them.
Finally, what you really wanted was to compute d-e, and you could give a hoot about the value of b. Anything like this will work:
double(dsol - esol)
ans = 3.0161
There are of course other things you can do. One nice idea is, since you really want the value of d-e, is to do a transformation of variables. This might make the problem simpler in some cases. For example, I'l create a new variable dminuse, such that
dminuse = d - e
Now, everywhere d appears in the problem, we can replace it by (dminuse + e).
syms dminuse
transeqn = subs(eqn,d,dminuse+e)
transeqn = 
The result is still a linear system of equations. We can solve it in variety of ways, as we have already seen. Here, I'll use vpasolve, since it gives us floating point results directly.
sol = vpasolve(transeqn,[b,e,dminuse])
sol = struct with fields:
b: 1.1534749850915482496738996567845 e: 1.9011417279491322809682487281326 dminuse: 3.0161042458038266745960650298759
So again, dminuse is 3.016....
Now, suppose we change the problem, in a way that makes the solve no longer give a unique answer?
For example, suppose I set up a system as:
eqnhat = eqn([1,2])
eqnhat = 
Now we have only two equations, but three unknowns. Can we infer the value of d-e now?
eqnhat = subs(eqnhat,d,dminuse + e) % the same trick as before
eqnhat = 
[Ahat,rhshat] = equationsToMatrix(eqnhat,[b e dminuse])
Ahat = 
rhshat = 
In fact, here we can see from the second of those two equations, that b and e are directly related, but that we do not know the value of either of them.
bhat = solve(eqnhat(2),b)
bhat = 
So, if we knew the value of e, then we can compute b. Now, substitute this into the first equation, and solve for dminuse.
ans = 
Again, the solution depends on an unknown parameter, and this is as much as we can do. Here, I have arbitrarily chosen e as the unknown parameter.
Different provblems arise if we have more equations than unknowns, but I feel I am already pushing the limits of what an answer can do, turning this into a class on how to solve systems of equations. And of course, if the system was not linear, then all hell breaks loose.
John D'Errico
John D'Errico on 2 Nov 2021
Good point. I had thought about an example where exactly that would happen, but there is a limit on the length of an answer too. :) And sometimes, if I get too elaborate in my comments, sometimes the message gets lost.

Sign in to comment.

More Answers (1)

Alan Stevens
Alan Stevens on 2 Nov 2021
These equations are linear in the unknowns, so can be solved as follows:
% M*X = V where X = [b; d; e]
% and the coefficients are in M,
% with the constants in V
M = [1/0.68, 1/1.8, -(1/1.8 + 1/3.3 + 1/0.68);
-(1/0.68 + 1/4.7 -1/1.5), 0, 1/0.68;
0, -(1/1.5 + 1/4.7 -1/1.8), -1/1.8];
V = [0; -(9/4.7+3/1.5); -9/1.5];
X = M\V;
b = X(1); d = X(2); e = X(3);
23.8313 -5.1692 13.8136
Alan Stevens
Alan Stevens on 2 Nov 2021
Yes, I just eyeballed the numbers as I wrote the matrix and vector. I should have taken more care!

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!