normal sum value and symsum value giving different result

2 visualizaciones (últimos 30 días)
TALACHEERU VENKATA ROHITH
TALACHEERU VENKATA ROHITH el 10 de Dic. de 2021
Respondida: Pavan Sahith el 13 de Feb. de 2024
syms m;
val1 = besseli(5,6)
val2 = symsum(besseli(m,6),m,5,5);
val3 = double(val2)
val1-val3
Output:
val1 =
7.9685
val3 =
7.9685
ans =
8.8818e-16
This difference is becoming huge for very large values such as besseli(5,56), etc. Can you explain me why this difference exist?

Respuestas (1)

Pavan Sahith
Pavan Sahith el 13 de Feb. de 2024
Hello Rohith,
As per my knowledge ,the reason for the difference between 'val1' and 'val3' in your MATLAB code is due to the way MATLAB handles symbolic computations using the "symsum" function.
  • In the case of 'val1', you are directly evaluating the Bessel function "besseli(5,6)" numerically and storing the result as a double-precision floating-point number.
  • In the case of 'val2', you are using the symsum function to symbolically compute the sum of Bessel functions. However, when you later convert it to a double with "double(val2)", MATLAB is performing a numerical approximation to evaluate the symbolic expression, and this can introduce some numerical error.
This discrepancy in the numerical approximation can lead to small differences between 'val1' and 'val3'. When dealing with symbolic computations, especially with functions that involve special functions like Bessel functions, numerical approximation errors can occur and accumulate, especially for large values.
Using vpa (Variable Precision Arithmetic) helps to achieve higher precision in symbolic computation and may reduce the discrepancy between val1 and val3.
val3 = vpa(val2);
You can refer to the following MathWorks documentation for more details
Hope that will help.

Categorías

Más información sobre Bessel functions en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by