vpasolve only shows 5 significant figures

Hello,
MATLAB help shows the following command should produce the result shown below
syms x
S = vpasolve(sin(x) == 1/2, x)
S = 
0.52359877559829887307710723054658
but on my machine it produces the following result
S = 0.5236
Similarly the command below should produce the result shown below
vpa(pi,10)
ans = 
3.141592654
but on my machine it produces the following result
ans = 3.1416
Why am I only getting 4 decimal places of precision? I've tried the digits(10) command but it doesn't help.
Any help greatly appreciated.
Thanks!

Answers (1)

Let's make sure you're using the functions from Symbolic Math Toolbox. What do these commands display?
which -all syms
/MATLAB/toolbox/symbolic/symbolic/syms.m
which -all vpasolve
/MATLAB/toolbox/symbolic/symbolic/@sym/vpasolve.m % sym method
which -all vpa
/MATLAB/toolbox/symbolic/symbolic/vpa.m /MATLAB/toolbox/symbolic/symbolic/@sym/vpa.m % sym method
Also what are your symbolic preferences? In particular, what is the FloatingPointOutput preference value?
sympref
ans = struct with fields:
FourierParameters: [1 -1] HeavisideAtOrigin: 1/2 AbbreviateOutput: 1 TypesetOutput: 1 FloatingPointOutput: 0 PolynomialDisplayStyle: 'default' MatrixWithSquareBrackets: 0

3 Comments

Hello Steven!
I get the following output:
>> which -all syms
\MATLAB\R2023a\toolbox\symbolic\symbolic\syms.m
>> which -all vpasolve
\MATLAB\R2023a\toolbox\symbolic\symbolic\@sym\vpasolve.m % sym method
>> which -all vpa
\MATLAB\R2023a\toolbox\symbolic\symbolic\vpa.m
\MATLAB\R2023a\toolbox\symbolic\symbolic\@sym\vpa.m % sym method
>> sympref
ans =
struct with fields:
FourierParameters: [1 -1]
HeavisideAtOrigin: 0.5000
AbbreviateOutput: 1
TypesetOutput: 1
FloatingPointOutput: 1
PolynomialDisplayStyle: 'default'
MatrixWithSquareBrackets: 0
I was able to change the FloatingPointOutput to 0 using
sympref('FloatingPointOutput',0)
and it seems to have fixed my issue! Not sure why it woudln't have been defaulted that way or how I would have changed it but I have it working now. thanks!!
Heh. I knew the cause of the problem from the Title to the question alone ;-)
Haha, Google Gemini needs to scrape your brain then because it didn't ;)
Thanks guys!

Sign in to comment.

Products

Release

R2023a

Asked:

on 1 Apr 2025

Commented:

on 2 Apr 2025

Community Treasure Hunt

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

Start Hunting!