Unable to get sym(pi) to output Pi in matlab

21 次查看(过去 30 天)
Shashank Namboodiri
Shashank Namboodiri 2024-10-22,1:30
回答: Paul 2024-10-22,2:07
I am unable to use sym(pi) to provide pi as an output.
syms n positive integer
syms x real
Pi = sym(pi);
a0 = 1/Pi * int(x, 0, Pi)
The output runs as
1.5708
This code ran on friend's laptop giving π/2 as output. What could be the reason?
  1 个评论
Torsten
Torsten 2024-10-22,1:36
编辑:Torsten 2024-10-22,1:37
Which MATLAB version do you use ? In R2024b, the output for a0 is pi/2.
syms n positive integer
syms x real
Pi = sym(pi);
a0 = 1/Pi * int(x, 0, Pi)

请先登录,再进行评论。

回答(1 个)

Paul
Paul 2024-10-22,2:07
Check your sympref
sympref
ans = struct with fields:
FourierParameters: [1 -1] HeavisideAtOrigin: 1/2 AbbreviateOutput: 1 TypesetOutput: 1 FloatingPointOutput: 0 PolynomialDisplayStyle: 'default' MatrixWithSquareBrackets: 0
Make sure that FloatingPointOutput is set to False.

标签

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by