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

29 ビュー (過去 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);
Leo Simon
Leo Simon 2017 年 10 月 13 日
Perfect, thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by