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

9 次查看(过去 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