Solve command in matlab not working?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kash Costello
el 7 de Jun. de 2018
Editada: John D'Errico
el 7 de Jun. de 2018
So my code is like this.
I have 4 unknowns: L, F, DMR, and D. I also have 4 equations. I already tried this code with 2 equations and 2 unknowns and they worked just fine for me. Now that I have four, I don't know why it's not working properly.
N1 = 76.045376620772100, N3 = 61.865859708789000, N5 = 52.463655388059650, N8 = 42.393818379746710
syms F D L DMR;
eqn1 = L*F*DMR == D*(N1*0.016);
eqn2 = L*F*DMR == (D+10)*(N3*0.016);
eqn3 = L*F*DMR == (D+20)*(N5*0.016);
eqn4 = L*F*DMR == (D+35)*(N8*0.016);
sol = solve([eqn1, eqn2, eqn3, eqn4], [F, D, L, DMR]);
FSol = sol.F;
DSol = sol.D;
LSol = sol.L;
DMRSol = sol.DMR;
% Converting Symbolic Number to Double Precision
symN = sym([FSol DSol LSol DMRSol]);
doubleN = double(symN);
F_answer=doubleN(1,1);
D_answer=doubleN(1,2);
L_answer=doubleN(1,3);
DMR_answer=doubleN(1,4);
Can someone help me determine the problem with my code? :(
Thank you!
0 comentarios
Respuesta aceptada
Torsten
el 7 de Jun. de 2018
Setting L*F*DMR = a, you can see that in reality, you don't have 4 equations in 4 unknowns, but only 4 equations in 2 unknowns. This means that usually, an exact solution to your problem does not exist.
An approximate solution "sol" can be obtained by
N1 = 76.045376620772100;
N3 = 61.865859708789000;
N5 = 52.463655388059650;
N8 = 42.393818379746710;
A = [1 -N1*0.016; 1 -N3*0.016; 1 -N5*0.016; 1 -N8*0.016];
b = [0 ; 10*N3*0.016 ; 20*N5*0.016 ; 35*N8*0.016];
sol = A\b;
LFDMR = sol(1)
D = sol(2)
res = A*sol-b
6 comentarios
Steven Lord
el 7 de Jun. de 2018
Nope, there's no way to compute L, F, and DMR to get "the" solution. You have one equation in three unknowns.
Suppose I tell you I'm thinking of two numbers whose product is 64. What are my two numbers? You can give A solution easily: choose a number N (not equal to 0) and tell me N and 64/N. It may or may not be MY solution, but you don't have enough information to know my solution. Your problem is similar, but with three numbers instead of two.
If I told you one more piece of information about my solution, like their sum or the value of one of the numbers, you'd have enough information to find my solution. In your case, you'd need two additional pieces of information. [Repeating the same information in a different form is not providing additional information. So saying that the product of their squares is 64^2 is not sufficient.]
Más respuestas (1)
John D'Errico
el 7 de Jun. de 2018
Editada: John D'Errico
el 7 de Jun. de 2018
The problem is not in solve. It is with your understanding of the mathematics.
You wrote this:
N1 = 76.045376620772100, N3 = 61.865859708789000, N5 = 52.463655388059650, N8 = 42.393818379746710
syms F D L DMR;
eqn1 = L*F*DMR == D*(N1*0.016);
eqn2 = L*F*DMR == (D+10)*(N3*0.016);
eqn3 = L*F*DMR == (D+20)*(N5*0.016);
eqn4 = L*F*DMR == (D+35)*(N8*0.016);
See that each equation has a left hand side of L*F*DMR.
You want to solve 4 equations, with the 4 unknowns L, F, DMR, D. If you could do so, you could think of it as if MATLAB found values for each of these variables.
But once MATLAB assigned a fixed value for each of L,F,DMR, that left hand side is now fixed in value. In each equation, the left hand side is the same!
L, F, DMR do not appear in any other place. So you could as easily have written it using ONE variable on the left hand side:
syms Q DMR;
eqn1 = Q == D*(N1*0.016);
eqn2 = Q == (D+10)*(N3*0.016);
eqn3 = Q == (D+20)*(N5*0.016);
eqn4 = Q == (D+35)*(N8*0.016);
There is only one piece of information in that product. At best, you can never determine the various factors of Q. Only the product, Q.
For example, suppose I gave you a similar problem, asking you to solve this problem?
x*y == 2
x*y == 3
What are the values of x and y that make those equations true?
Can you find ANY such values, that will satisfy BOTH equations? Feel free to try using the symbolic toolbox. It will fail to produce something useful. Can I argue that I posed two equations in two unknowns. So surely a solution must exist?
At the very best, I might find some value of the product, x*y, that will make both equations as close to true as possible. Here, I suppose that would result in the product x*y=2.5. But does that provide sufficient information to infer the values of both x and y? Are you kidding?
Can you see that what you did was equally impossible to solve?
At best, you can try to approximately solve the problem as I wrote it with Q on the left hand side. But you can never infer the values of L,F,DMR separately.
4 comentarios
John D'Errico
el 7 de Jun. de 2018
Editada: John D'Errico
el 7 de Jun. de 2018
Suppose I told you that a*b*c = 12.
What values do each of them take? Is it, [1,3,4]? Maybe [1 1 12]? How about if they are all the cube root of 12?
There is no way to resolve a product into elements. Infinitely many solutions, all equally good. So no unique solution.
But in this case, it is worse, since you have essentially only 2 variables in 4 equations. So you will have no solution that solves all 4 equations at once, exactly. And even when you do as well as possible in a least squares sense, that still leaves you with no way to uniquely resolve the ambiguities remaining.
So, why were you able to resolve the problem with only 2 unknowns, in 2 equations? What was fundamentally different?
Lets pose several systems of 2 equations in 2 unknowns.
x + y = 1
x - y = 3
Trivial to solve. A unique solution exists. But what if we did this?
x + y = 1
x + y = 2
Surely you would admit that no unique solution exists? That even if you choose some values for x and y that solve the problem in a least squares sense, they won't be unique. So if I pick any pair of values for x and y, call them x0 and y0, then [xo+k,y0-k] is just as good, for ANY value of k? The second pair of equations are impossible to solve. They represent parallel, non-intersecting lines.
Now, consider a problem in the form you have posed it.
x*y = 1
x*y = 2
They are equalities. I could take logs. Then do a transformation. So write it as
u = log(x)
v = log(y)
Then the above product equations can be re-written in the form:
u + v = log(1)
u + v = log(2)
In the transformed domain, we have parallel, non-intersecting lines. In the x-y plane, they would look like "parallel" non-intersecting hyperbolic arcs.
So we are essentially back to the case of parallel, non-intersecting lines. And that is what you have created in your problem.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!