4
$\begingroup$

I have a system of seven nonlinear equations that I want to find their symbolic solutions. The solution will depend on the parameter K, and I should have different solutions by varying the parameter. I want the program to give the ranges of K and the solution associated with each value. I tried to solve the system using matlab symbolic toolkit. The code I used is:

syms K x  y  z  u  v  w  p; 

eq1 =  -2*x - 4*u*v + 4*y*p == 0;

eq2 =  -9*y +3*x*p == 0;

eq3 =  -4*z - 4*sqrt(2)*u*w + 4*sqrt(2)*w*p  + 4*K == 0;

eq4 =  -5*u + x*v + 3*sqrt(2)*z*w == 0;

eq5 =  -v + 3*x*u - sqrt(5)*x*w == 0;

eq6 =  -w + sqrt(5)*x*v + sqrt(2)*z*u - sqrt(2)*z*p == 0;

eq7 =  -5*p - 7*x*y - 3*sqrt(2)*z*w == 0;

[x y z u v w p] = solve(eq1, eq2, eq3, eq4,eq5, eq6, eq7)

I run the code using matlab R2015b, and after running for abut 6 hours it either give an empty solution or stops working. Any advice?

$\endgroup$
14
  • 3
    $\begingroup$ You are trying to find an analytic solution to an equation that may not have one that can be expressed in terms of formulas. Why not solve it numerically (i.e., without syms)? $\endgroup$ Dec 29, 2015 at 17:16
  • 3
    $\begingroup$ Although you are using Matlab code in your Question, note that SciComp.SE also supports mathematical expressions by MathJax and $\LaTeX$ syntax. $\endgroup$
    – hardmath
    Dec 29, 2015 at 17:17
  • 3
    $\begingroup$ Maple finds a symbolic solution, but in terms of roots of high degree (10th degree) polynomials. $\endgroup$ Dec 30, 2015 at 0:32
  • 1
    $\begingroup$ @choward That -- depending on the conditioning of the nonlinear system -- a small residual (say 1e-12) doesn't necessarily correspond to a small error (distance of approximation to a true root, which could even be O(1) if the system is ill-conditioned enough). $\endgroup$ Jan 1, 2016 at 11:05
  • 2
    $\begingroup$ In these cases, the usual choice is comparing the numerical solution with a numerical one computed with a higher precision. An "analytical solution" does not necessarily give the correct answer: every formula needs to be evaluated numerically. Even for a second-degree equations, computing the "analytical solution" with the textbook formula $\frac{b\pm \sqrt{b^2-4ac}}{2a}$ can be significantly less accurate than a numerical solution computed with Newton's method. Take a case in which $b \gg 4ac$, for instance. $\endgroup$ Jan 1, 2016 at 17:37

1 Answer 1

3
$\begingroup$

Don't use Matlab.

The symbolic toolbox in Matlab is useful for computing the derivative, integral or root of simple functions to be used in further numerical computation, but cannot compete with modern computer algebra systems (CAS) such as Maple, Magma or Singular. So if Matlab fails to compute a solution, you should try one of these.

If you just want to plot the solution(s) as a function of the parameter, that can usually be done within the package (not sure about Magma, though). If you want to use the results in further (numerical) computation, you can use Maple's CodeGeneration module to generate a Matlab function that evaluates the solution for a given parameter. You could also implement everything within the general purpose Sage framework, which bundles (among many others) Singular together with NumPy, SciPy and Matplotlib (which together provide similar features to Matlab).

One thing to keep in mind is that solutions provided by a CAS are very likely to be in terms of mathematical objects (such as tenth roots, as Brian Borchers points out is the case in your problem) that cannot be represented numerically -- and hence plotted, or used in further computations -- exactly. So you are once more limited to a numerical approximation, which might(!) be no better than the one you computed. (It usually is, but it's something to be aware of.)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.