Why is MATLAB throwing a 'Reference to non-existent field' error when using Solve on a system of linear equations? How can I find my answer?

1 view (last 30 days)
Hi,
I'm just getting into using MATLAB and I'm currently trying to get it to crunch some algebra for me.
I've attached an image of the procedure that I go through that results in the error being thrown.
The syms that I create are cleared before I create them.
Solve manages to pump out equations for the variables Va, Vb and Vc yet is unable to do it for the R values that I request. This occurs if I provide numerical values to other variables or if it is done all symbolically. You can see an example of where I provide numerical values in the bottom portion of the image attached.
What could be causing the non-existent field error?
Thanks for your time, I'm happy to provide any more information if it makes answering this question easier.
Tom.
EDU>> syms Va Vb Vc R1 R2 R3 R4 R5 R6 R7 Vs
syms Va Vb Vc R1 R2 R3 R4 R5 R6 R7 Vs
EDU>> eqns = [(Vs-Va)/R1 == Va/R2 + (Va-Vb)/R3 + (Va-Vc)/R5, (Va-Vb)/R3 == Vb/R4 + (Vb-Vc)/R6, (Vb-Vc)/R6 + (Va-Vc)/R5 == Vc/R7];
EDU>> S = solve(eqns);
EDU>> sol = [S.Va; S.Vb; S.Vc]
sol =
(R2*Vs*(R3*R4*R5 + R3*R4*R7 + R3*R5*R6 + R3*R5*R7 + R4*R5*R6 + R3*R6*R7 + R4*R5*R7 + R4*R6*R7))/(R1*R2*R3*R4 + R1*R2*R3*R6 + R1*R2*R4*R5 + R1*R2*R3*R7 + R1*R2*R4*R6 + R1*R3*R4*R5 + R1*R2*R5*R6 + R2*R3*R4*R5 + R1*R2*R5*R7 + R1*R3*R4*R7 + R1*R3*R5*R6 + R1*R2*R6*R7 + R1*R3*R5*R7 + R1*R4*R5*R6 + R2*R3*R4*R7 + R2*R3*R5*R6 + R1*R3*R6*R7 + R1*R4*R5*R7 + R2*R3*R5*R7 + R2*R4*R5*R6 + R1*R4*R6*R7 + R2*R3*R6*R7 + R2*R4*R5*R7 + R2*R4*R6*R7)
(R2*R4*Vs*(R3*R7 + R5*R6 + R5*R7 + R6*R7))/(R1*R2*R3*R4 + R1*R2*R3*R6 + R1*R2*R4*R5 + R1*R2*R3*R7 + R1*R2*R4*R6 + R1*R3*R4*R5 + R1*R2*R5*R6 + R2*R3*R4*R5 + R1*R2*R5*R7 + R1*R3*R4*R7 + R1*R3*R5*R6 + R1*R2*R6*R7 + R1*R3*R5*R7 + R1*R4*R5*R6 + R2*R3*R4*R7 + R2*R3*R5*R6 + R1*R3*R6*R7 + R1*R4*R5*R7 + R2*R3*R5*R7 + R2*R4*R5*R6 + R1*R4*R6*R7 + R2*R3*R6*R7 + R2*R4*R5*R7 + R2*R4*R6*R7)
(R2*R7*Vs*(R3*R4 + R3*R6 + R4*R5 + R4*R6))/(R1*R2*R3*R4 + R1*R2*R3*R6 + R1*R2*R4*R5 + R1*R2*R3*R7 + R1*R2*R4*R6 + R1*R3*R4*R5 + R1*R2*R5*R6 + R2*R3*R4*R5 + R1*R2*R5*R7 + R1*R3*R4*R7 + R1*R3*R5*R6 + R1*R2*R6*R7 + R1*R3*R5*R7 + R1*R4*R5*R6 + R2*R3*R4*R7 + R2*R3*R5*R6 + R1*R3*R6*R7 + R1*R4*R5*R7 + R2*R3*R5*R7 + R2*R4*R5*R6 + R1*R4*R6*R7 + R2*R3*R6*R7 + R2*R4*R5*R7 + R2*R4*R6*R7)
EDU>> Vs = 5
Vs =
5
EDU>> Va = 3; Vb = 1; Vc = 2;
EDU>> R1 = 1000; R3 = 1000; R5 = 1000; R6 = 1000;
EDU>> S = solve(eqns);
EDU>> sol= [S.R2; S.R4; S.R7]
Reference to non-existent field 'R2'.

Answers (1)

Walter Roberson
Walter Roberson on 2 Aug 2015
When you assign a numeric value to a variable, it does not change the evaluation of any symbolic formula that involved those variables. To import the numeric values from the workspace in to the symbolic formula, you need to use subs(), such as
eqns2 = subs(eqns)
sols = solve(eqns2)
If you do this then you will find that sols is empty. This is due to the fact that the third component of the equation
(Vb-Vc)/R6 + (Va-Vc)/R5 == Vc/R7
will evaluate to become
0 = 2/R7
This has no consistent solution; the closest you could get would be if you let R7 be infinity. The symbolic engine will not find that solution, though: it would try to bring the R7 up and find that it is working with 0*R7 = 2 and it would give up on that.
Remember that you should test for empty solution before you assume that a field exists.
You should also get in the habit of specifying which variables to solve for; sometimes that can make a big difference in what is returned.
  2 Comments
Thomas Marsden
Thomas Marsden on 2 Aug 2015
Thanks a lot for your answer! It makes a lot of sense now. Would I be correct in saying that the foundation of my problem is what I'm trying to solve for within the equation? Cheers
Walter Roberson
Walter Roberson on 2 Aug 2015
Not exactly: you have simply forgotten to account for singularities, for the places where the equations have no solutions.
Symbolically, R7 = Vc*R6*R5/((Vb-Vc)*R5+R6*(Va-Vc)) so if ((Vb-Vc)*R5+R6*(Va-Vc)) = 0 then you have a singularity.
If you suspect a singularity then you can take the denominator of each term and solve() for that being 0 in terms of one of the variables. If you do that you will find that your equations are singular if R6 = (Vb-Vc)*R3/(Va-Vb) or R6 = -(Vb-Vc)*R5/(Va-Vc) . Remember to watch out for singularities in those expressions!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!