Symbolic Output Display Problem

17 views (last 30 days)
I have a long symbolic expression where the output display gives unwanted fraction representations. An example of the output is given below. The unwanted fraction is given in bold. I've attached the m.file used to generate the output. You can see that this fraction is not contained in the input definition of c111r. I have tried various commands such as "sym(5^(1/2))" to prevent this from happening without success. Any help would be greatly appreciated. I am using MatlabR2013b.
c111r =
(((((c11 + c12)/((c11 - c12)*(c11 + 2*c12)) - 1/(2*c44) + c12/((c11 - c12)*(c11 + 2*c12)))*((16*2^(1/2)*pi^2*W400)/35 + (16*5^(1/2)*pi^2*W420)/35 - 1/5) + c12/((c11 - c12)*(c11 + 2*c12)))*(((c11 + c12)/((c11 - c12)*(c11 + 2*c12)) - 1/(2*c44) + c12/((c11 - c12)*(c11 + 2*c12)))*((16*5^(1/2)*pi^2*W420)/35 - (16*2^(1/2)*pi^2*W400)/35 + 1/5) - c12/((c11 - c12)*(c11 + 2*c12))) + (((c11 + c12)/((c11 - c12)*(c11 + 2*c12)) - 1/(2*c44) + c12/((c11 - c12)*(c11 + 2*c12)))*((4*2^(1/2)*pi^2*W400)/35 - (8*35^(1/2)*pi^2*W440)/35 + 1/5) - c12/((c11 - c12)*(c11 + 2*c12)))*(1/(2*c44) + ((32*2^(1/2)*pi^2*W400)/35 + 3/5)*((c11 + c12)/((c11 - c12)*(c11 + 2*c12)) - 1/(2*c44) + c12/((c11 - c12)*(c11 + 2*c12))) - c12/((c11 - c12)*(c11 + 2*c12))))^3*(((3*c144*(c11 + c12))/((c11 - c12)*(c11 + 2*c12)) - (6*c12*c155)/((c11 - c12)*(c11 + 2*c12)))/(2*c44^2) - c112*((6*c12^3)/((c11 - c12)^3*(c11 + 2*c12)^3) + (6*c12*(c11 + c12)^2)/((c11 - c12)^3*(c11 + 2*c12)^3) - (6*c12^2*(c11 + c12))/((c11 - c12)^3*(c11 + 2*c12)^3)) - (((c144*(c11 + c12))/((c11 - c12)*(c11 + 2*c12)) - (2*c12*c155)/((c11 - c12)*(c11 + 2*c12)))/(4*c44^2) - (c155*((c11 + c12)/((c11 - c12)*(c11 + 2*c12)) - c12/((c11 - c12)*(c11 + 2*c12))) - (c12*c144)/((c11 - c12)*(c11 + 2*c12)))/(4*c44^2) + c456/(4*c44^3))* *((269741649381513*pi^2*W420)/21990232555520 + (2497842628749521*pi^2*W440)/153931627888640* +...

Accepted Answer

Star Strider
Star Strider on 10 Jun 2014
Meet the vpa function and its friends (linked to at the end of the vpa page).
  3 Comments
Star Strider
Star Strider on 10 Jun 2014
Sorry vpa, digits or double didn’t work. I too wish the Symbolic engine resisted the temptation to produce rational fractions by default instead of keeping everything as the integers or fixed-precision floats it started with, unless requested to evaluate them.
My only other suggestion is to experiment with assume. Sometimes that keeps things symbolic when they might otherwise be evaluated.
Christopher Kube
Christopher Kube on 11 Jun 2014
I was able to fix this by declaring my initial expression as a character string and then inputting this into the sym function.
c111r = '((16*2^(1/2)*pi^2*W400)/35 + (16*5^(1/2)*pi^2*W420)/35 - 1/5)'; c111r = sym(c111r);
This output does not result in a different form from the input.
This is important since I may want to simplify, expand, or latex these equations. For example, I certainly don't want those "many digit fractions" in my latex output.

Sign in to comment.

More Answers (1)

Christopher Creutzig
Christopher Creutzig on 1 Sep 2014
If I understand your problem correctly, you don't want approximations as given by vpa. In that case, here's the best advice I can give without seeing your inputs:
Don't use calls like sym(5^(1/2)) (although that particular one works just fine), use sym(5)^(1/2) instead.
If you say, e.g., sym(5^(1/3)), that will be the same as saying sym(1.709975946676697) and will not magically detect that you meant 5^(1/3), not 1925261759066421/1125899906842624. I.e., if your input contains sym(5^(1/3)), it contains a rational number with large numerator and denominator, which will show up in the output.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!