4

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?

Federico Poloni
  • 11,344
  • 1
  • 31
  • 59
Alaa
  • 41
  • 3
  • 3
    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)? – Wolfgang Bangerth Dec 29 '15 at 17:16
  • 3
    Although you are using Matlab code in your Question, note that SciComp.SE also supports mathematical expressions by MathJax and $\LaTeX$ syntax. – hardmath Dec 29 '15 at 17:17
  • Thanks for the reply, but I already have the numerical solution. I just need the analytical one – Alaa Dec 29 '15 at 18:11
  • If this problem doesn't have an analytical solution, the best thing I can see you trying is solving the system numerically with various different values for K (assuming you have an idea of what range of values K might be) and then trying to fit the resulting data for each of the variables you solve for. At least then you might have a fairly robust approximate mapping from K to each variable. – spektr Dec 29 '15 at 21:22
  • 3
    Maple finds a symbolic solution, but in terms of roots of high degree (10th degree) polynomials. – Brian Borchers Dec 30 '15 at 00:32
  • You might wish to try a more modern Computer Algebra System such as Singular. You can try it out online; how to solve polynomial systems is described here. An alternative is Magma. – Christian Clason Dec 30 '15 at 11:55
  • @Alaa It would help to answer your question if you told us what you wish to do with the results (plot them? use them as input in further (numerical or symbolic) computations?) – Christian Clason Dec 30 '15 at 12:32
  • I want to plot the analytical versus the numerical, I will try the suggestions you gave. Thanks @ChristianClason – Alaa Dec 30 '15 at 15:25
  • @Alaa If you are trying to compare numerical solution to the true one, don't you think you could just plot the residuals of each equation using the numerical solution? Because we know the true solution will make those residuals all 0. That would then show you how close your numerical solution is to being correct. – spektr Dec 30 '15 at 15:56
  • @choward Depending on the conditioning of the system, a close-to-zero residual doesn't necessarily imply a close-to-zero solution. – Jeff Irwin Dec 31 '15 at 19:19
  • @JeffIrwin I don't feel I know what you mean by a close-to-zero solution in the way you mentioned it. Given the OP wants to make each equation equal to zero, and given that a true solution should result in each equation having a zero residual, I would think showing the residuals of all the equations approaching zero would show it's getting close to the unknown true solution. What am I misunderstanding about what you said? – spektr Dec 31 '15 at 21:25
  • 1
    @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). – Christian Clason Jan 01 '16 at 11:05
  • @ChristianClason alright, that makes sense! – spektr Jan 01 '16 at 14:55
  • 2
    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. – Federico Poloni Jan 01 '16 at 17:37

1 Answers1

3

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.)

Christian Clason
  • 12,301
  • 3
  • 48
  • 68