Prevent automatic simplification of a symbolic expression when using the latex command

조회 수: 7 (최근 30일)
I have the following expression
f = @(k,n)1.0./n.^(2.0./3.0).*(6.0.^(1.0./3.0).*k.^(1.0./3.0).*4.0-k.*n.^(2.0./3.0).*1.2e1).*(-1.0./3.0)
and when I write
latex(f(k,n))
I get the hideous expression
\frac{12\, k\, n^{\frac{2}{3}} - \frac{8183583624766079\, k^{\frac{1}{3}}}{1125899906842624}}{3\, n^{\frac{2}{3}}}
Obviously matlab is doing some simplifications along the way. Is there any way to get the latex command to output the original expression for f that I typed in, without making any simplifications?
Thanks for any advice

채택된 답변

Walter Roberson
Walter Roberson 2017년 10월 13일
No, that is not possible in any easy way.
When you invoked f(k,n) to turn the function handle into a sym so you could call latex(), then you requested evaluation of the function. Evaluation of symbolic functions always involves automatic simplification of constant expressions and automatic combination of constant terms, along with various automatic rewriting of term order according to rules that can be difficult to work out.
I have to wonder, though, where that code came from? It looks suspiciously like something that would be generated by matlabFunction() applied to a symbolic expression; if so then possibly you can latex() the symbolic expression directly.
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 10월 13일
syms k_r k_n n positive
assumeAlso(k_n > k_r);
f = @(k_r,n) -sym(2)*( sym(6)^(sym(1)/sym(3))/sym(2)* (n*abs(k_r)).^(-sym(2)/sym(3)) - sym(1) ).*k_r.^sym(2) ;
df_form = simplify(diff(f(k_r,n),k_r));
df_latex = latex(df_form);
df = matlabFunction(df_form);

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

추가 답변 (0개)

카테고리

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