normal sum value and symsum value giving different result

조회 수: 2 (최근 30일)
TALACHEERU VENKATA ROHITH
TALACHEERU VENKATA ROHITH 2021년 12월 10일
답변: Pavan Sahith 2024년 2월 13일
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?

답변 (1개)

Pavan Sahith
Pavan Sahith 2024년 2월 13일
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.

카테고리

Help CenterFile Exchange에서 Bessel functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by