Help with displayFormula from symbolic math toolbox

23 ビュー (過去 30 日間)
andrea
andrea 2020 年 3 月 8 日
回答済み: Christopher Creutzig 2020 年 3 月 9 日
Hello everyone, i've got a simple question but i can't find the answer in the forum:
The function displayFormula from the symbolic math toolbox is working only in live editor , I mean it gives output only if used in a .mlx script.Is this the way it's supposed to work or there is a way to use this function even in the command window ?
Thanks in andvace.

回答 (1 件)

Christopher Creutzig
Christopher Creutzig 2020 年 3 月 9 日
Rendered formulas are only available in Live Editor, whether you use displayFormula or just have standard output.
In Command Window, formulas are shown as plain old text, but the substitutions of displayFormula still do take place. E.g., here are the second and third example from the documentation:
>> S = "m*diff(y,t,t) == m*g-k*y";
>> symstr = ["'The equation of motion is'"; S;"'where k is the elastic coefficient.'"];
>> displayFormula(symstr)
The equation of motion is
m*diff(y, t, t) == m*g - k*y
where k is the elastic coefficient.
>> S = "exp(2*pi*i)";
>> symstr = "1 + S + S^2 + cos(S)";
>> displayFormula(symstr)
1 + exp(2*pi*1i) + exp(2*pi*1i)^2 + cos(exp(2*pi*1i))
Note that this last output would automatically simplify if used as a sym:
>> 1 + exp(2*sym(pi)*1i) + exp(2*sym(pi)*1i)^2 + cos(exp(2*sym(pi)*1i))
ans =
cos(1) + 3

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by