Help with displayFormula from symbolic math toolbox

23 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by