Having issues with precision output of symbolic expression for a Legendre polynomial.
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nathan Biggers
le 4 Mai 2022
Commenté : Walter Roberson
le 4 Mai 2022
I am trying to determine the roots of a 3rd degree Legendre Polynomial so I can create a Gaussian Quadrature function. I am having issues with the output precision on 2021b and 2022a. I have tried both versions (updating to 2022a did not resolve my issue). The symbolic or double output only goes to 4 decimals, regardless of the formatting, or method of solving. I have spent a few hours reading through vpa, solve, symbolic, double, and format documentation and have not been able to resolve my issue. MATLAB online does not have issues with the output, but I do not understand why the desktop version (either) does not work properly. If anyone could help explain why the desktop version might be doing this, and provide a solution, that would be great!
I have tried every combination of double() or vpa() that I can think of to try and make this work. I have posted what I am getting stuck on below, with the expected results vs what I am getting. Changing the degree of the polynomial does not resolve my precision issue either. I have also browsed through my variable settings and tried changing default array format to long and long g.
% Method 1 - numerically solve
syms x
vpasolve(legendreP(3, x) == 0)
% Method 2 - symbolically solve and convert to double
syms x
l = legendreP(3, x);
vpa(solve(l, x))
% double(solve(l, x)) does not work either
% Method 3 - format output
format long
format long g
syms x
vpasolve(legendreP(3, x) == 0)
% Method 4 - anonymous function
l = @(x) legendreP(3, x);
solve(l(x), x)
vpasolve(l(x), x) % this does not work either
% Expected results:
-0.77459666924148337703585307995648
0
0.77459666924148337703585307995648
% Actual results:
-0.7746
0
0.7746
0 commentaires
Réponse acceptée
Walter Roberson
le 4 Mai 2022
sympref('FloatingPointOutput', 0)
2 commentaires
Walter Roberson
le 4 Mai 2022
When the opposite is in effect, symbolic output is passed through vpa(Expression, 4)before being output.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Conversion Between Symbolic and Numeric dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!