why is the "pretty" command does not work in the script,but works when I press it in the command windo?

10 次查看(过去 30 天)
hello I have this command
syms A D k x_0
eqn_1=A*(exp(k*x_0)-exp(-k*x_0))==D*exp(-k*x_0)
eqn_2=-k*D*exp(-k*x_0)-k*A*(exp(k*x_0)+exp(-k*x_0))==1
sol = solve([eqn_1, eqn_2], [A D ])
A=(sol.A)
D=(sol.D)
A=pretty(A)
D=pretty(D)
my question is why when the pretty comand apprers in the script it does not work but when i press the command in the command window it works ?

回答(1 个)

Stephan
Stephan 2018-6-5
Hi,
try this:
syms A D k x_0
eqn_1=A*(exp(k*x_0)-exp(-k*x_0))==D*exp(-k*x_0)
eqn_2=-k*D*exp(-k*x_0)-k*A*(exp(k*x_0)+exp(-k*x_0))==1
sol = solve([eqn_1, eqn_2], [A D ])
A=(sol.A)
D=(sol.D)
pretty(A)
pretty(D)
This gives you:
A =
-exp(-k*x_0)/(2*k)
D =
-(exp(k*x_0) - exp(-k*x_0))/(2*k)
exp(-k x_0)
- -----------
2 k
exp(k x_0) - exp(-k x_0)
- ------------------------
2 k
The way you did it makes an error in both cases (command window and script):
Error using sym/pretty
Too many output arguments.
So use:
pretty(A)
pretty(D)
instead of
A = pretty(A)
D = pretty(D)
Best regards
Stephan

类别

Help CenterFile Exchange 中查找有关 Elementary Math 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by