Symbolic Output Display Problem

조회 수: 19 (최근 30일)
Christopher Kube
Christopher Kube 2014년 6월 10일
답변: Christopher Creutzig 2014년 9월 1일
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* +...

채택된 답변

Star Strider
Star Strider 2014년 6월 10일
Meet the vpa function and its friends (linked to at the end of the vpa page).
  댓글 수: 3
Star Strider
Star Strider 2014년 6월 10일
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 2014년 6월 11일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Christopher Creutzig
Christopher Creutzig 2014년 9월 1일
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.

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by