MATLAB solve function is taking a very long time
58 views (last 30 days)
Show older comments
Hello,
I have a system of 17 equations and 23 unknowns and I'm using the MATLAB "solve" function to solve symbolically for 17 unknowns in terms of the other 6 unknowns. However, the "solve" function has been running for several hours and still has not gotten a solution.
I have used the MATLAB "solve" function in this way for several small systems of equations and it finds a solution very quickly (within minutes). Does anyone have any ideas as to why the "solve" function is taking so long in this instance? What is generally the upper limit of equations that the "solve" function can solve in a reasonable amount of time? (I know there is an upper limit to the number of equations that can be handled, but I'm very surprised that 17 equations is taking so long.) Does anyone have any ideas as to anything I can try (maybe options to use with the solve function, or some other function to use) in order to get a solution for my system of equations?
Thank you,
Kevin
0 Comments
Accepted Answer
Walter Roberson
on 10 Apr 2013
The upper limit to the number of equations that solve() can resolve in a reasonable amount of time depends upon whether the equations are linear or not. If they are non-linear (including even just squared terms) then 4 can usually be done fairly quickly, 5 is about the practical limit, and 6 might take days.
The limits are slightly higher if you happen to have the Maple based symbolic toolbox and are using just squared terms, but even for that, 6 might take overnight and 7 is unlikely to finish after several days.
6 Comments
More Answers (1)
Ahmed A. Selman
on 10 Apr 2013
Sometimes trying the (simplify) command successively after each solve command, helps making the syms math incredibly faster. It helps when the result of a mathematical operation in a certain operation is to be used in a following one. For example, it might take long time to find D if B was a complicated expression in:
...
B=solve(function_Of_x_y_z);
D=solve(function_of_B);
adding the simplify usually helps reducing the runtime as:
...
B=solve(function_Of_x_y_z);
B=simplify(B);
D=solve(function_of_B);
even multiple simplifies can be useful as:
...
B=solve(function_Of_x_y_z);
B=simplify(simplify(B));
D=solve(function_of_B);
Note that simplify command by itself takes some extra time to finish, yet it helps since syms math operations depends on the length of the expressions. So
u = x^2 + 4*x + 4*cos(2*x)^2 + 4*sin(2*x)^2; % This is a lengthy expression
u = simplify(u);% Results, equivalently, u = (x + 2)^2.
2 Comments
Ahmed A. Selman
on 10 Apr 2013
17 unknowns with a SINGLE equation? How is that mathematically possible.. even if they are in a linear form. Besides, suppose I have the equation:
y(x)= a*x+c,
it might be mathematically equivalent to, e.g.,
y(x1,x2)= a*x1 + b*x2 + c,
if we let A={a,b}, X={x1,x2}, then Y={y(x1,x2)} leading to
Y=A*X +b .. etc,
But, the function y(x) can be solved when
y(x)=0 -- single variable (x), with a single condition
but not
y(x1,x2)=0 -- two variables, with a single condition.
Simply, it is impossible to solve for x1 or x2 only (as x1=a or x2=b/c.. etc). The only possibility is to have a solution like :
x1= -(c+b*x2)/a -- still a function of x2.
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!