Symbolic equation is too long to be displayed.

17 views (last 30 days)
Hello. I want to solve the equation v = 0 for x, many many times, for different values of P, dd and tc. Using matlabs solve-function to find the solution takes too much time. I am trying a different approach, to avoid using the solve-function. First: Use the solve-function to find the "symbolic" expression of x. Then: Copy the equation I get and paste it into my function, hoping this will be faster. When I try to do this, (as showed bellow), I dont get the whole expression for x, because the expression is too long, and I get the message: Output truncated. Text exceeds maximum line length of 25 000 characters for Command Window display. So, my questions are: How can I get the whole expression? Or, can I use the expression I get from solve to find x, without pasting the whole expression into my function? Is there a faster way to solve this problem?
x = sym('x');
P = sym('P', [3 3]);
dd = sym('dd', [1 3]);
tc = sym('tc', [1 3]);
t2 = (tc - x)./dd;
v = t2*P^-1*s^2*(P^-1).'*t2.'-1;
x = solve(v,x)
x =
(2*P1_1^2*P2_2^2*dd1^2*dd2^2*s^2*tc3 + 2*P1_2^2*P2_1^2*dd1^2*dd2^2*s^2*tc3 + ..............more letters............... + P1_3*P2_1*P3_2 - P1_3*P2_2*P3_1)) - (P1_1*P3_3 - P1_3*P3_1)/(dd2*(P1_1*P2_2*P3_3 - P1_1*P2_3*P3_2 - P1_2*... Output truncated. Text exceeds maximum line length of 25 000 characters for Command Window display.
(2*P1_1^2*P2_2^2*dd1^2*dd2^2*s^2*tc3 + .....More letters........ - (P1_1*P3_3 - P1_3*P3_1)/(dd2*(P1_1*P2_2*P3_3 - P1_1*P2_3*P3_2 - P1_2*... Output truncated. Text exceeds maximum line length of 25 000 characters for Command Window display.
It works for the two dimensional problem. I found the symbolic equation for x using solve, and pasted it into my function. The two solutions of x, xxP and xxM, are found and the equations looks like this: (Pi_j, ddi, s and tci are known)
xxP = (P1_1^2*dd1^2*s*tc2 + P1_2^2*dd2^2*s*tc1 + P2_1^2*dd1^2*s*tc2 + P2_2^2*dd2^2*s*tc1 + P1_1*P2_2*dd1*dd2*(P1_1^2*dd1^2 - 2*P1_1*P1_2*dd1*dd2 + P1_2^2*dd2^2 + P2_1^2*dd1^2 - 2*P2_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^2*dd1^2 - 2*s*P2_1*P2_2*dd1*dd2 + s*P2_2^2*dd2^2);
All help is appreciated. -Cecilia.

Accepted Answer

Roger Stafford
Roger Stafford on 18 Aug 2014
Your 25000-plus-character result demonstrates the perils of attempting to always obtain a single symbolic expression as the solution to a problem. In this case you have nothing more than a quadratic equation in the unknown x to solve, and the best way to solve it is to do so in steps. Step one would be to evaluate the inverse matrix, P^-1, from P. The second step is to compute
T = P^-1*s^2*(P^-1).'
The third step is to use T, tc, and dd to compute the three coefficients in the quadratic equation - that is, to gather all the terms containing x^2, those containing x, and those independent of x. The fourth step is the trivial one of solving for the two roots of the resulting quadratic equation.
Each of these steps can be accomplished symbolically, but as you have found out the hard way, it is unwise to attempt to combine the results of these steps into a single symbolic expression. There is nothing wrong with expressing a solution in terms of a sequence of symbolic procedures.
  4 Comments
Cecilia
Cecilia on 27 Aug 2014
It subtracts x from all the elements, that is:
t2 =
[ (tc1 - x)/dd1, (tc2 - x)/dd2, (tc3 - x)/dd3].
Solving the problem using solve(v,x) gives the correct answer, but it takes nearly two hours solving the whole thing. Solving it the way you suggested takes 5 minutes, but the answer is not correct. I do not understand why.
Cecilia
Cecilia on 27 Aug 2014
Oh, I forgot the -1 in the c-term, c = W*T*W.'-1. Im so sorry bothering you, everything works now, thank you for your help.

Sign in to comment.

More Answers (0)

Categories

Find more on Partial Differential Equation 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!