MATLAB: Eval returns NaN when the number “r” gets too large

eval() returns nan when my matrix gets really bigthe evil eval

Good morning, i am doing a numerical integration and I need to evaluate the equation below for r = 0.538469810105683 which is a large number but necessary for accurate solution. When I verify the result turns out to be very large and it just appears NaN. What should I do, please any help will be very supporting. Thanks in advance
g(r)=(12*(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 – (12*r + 12)^3/144115188075855872 – 1688849860263933/281474976710656)^2 + 1)^(1/2)*((15554*r^6)/625 – (19998*r^7)/625 + (140007*r^5)/5000 – (20001*r^4)/1000 – 5*r^3 + 3*r^2 + (417*r)/2500 – 139/2500) – (12*((27*r)/1125899906842624 – (9*(12*r + 12)^2)/36028797018963968 + 39/1125899906842624)^2*((1111*r^9)/2500 – (1111*r^8)/2500 – (6667*r^7)/10000 + (6667*r^6)/10000 + r^5/4 – r^4/4 – (139*r^3)/5000 + (139*r^2)/5000))/(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 – (12*r + 12)^3/144115188075855872 – 1688849860263933/281474976710656)^2 + 1)^(1/2) – (24*((27*r)/1125899906842624 – (9*(12*r + 12)^2)/36028797018963968 + 39/1125899906842624)*((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 – (12*r + 12)^3/144115188075855872 – 1688849860263933/281474976710656)*((9999*r^8)/2500 – (2222*r^7)/625 – (46669*r^6)/10000 + (20001*r^5)/5000 + (5*r^4)/4 – r^3 – (417*r^2)/5000 + (139*r)/2500))/(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 – (12*r + 12)^3/144115188075855872 – 1688849860263933/281474976710656)^2 + 1)^(1/2) + (12*((27*r)/1125899906842624 – (9*(12*r + 12)^2)/36028797018963968 + 39/1125899906842624)^2*((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 – (12*r + 12)^3/144115188075855872 – 1688849860263933/281474976710656)^2*((1111*r^9)/2500 – (1111*r^8)/2500 – (6667*r^7)/10000 + (6667*r^6)/10000 + r^5/4 – r^4/4 – (139*r^3)/5000 + (139*r^2)/5000))/(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 – (12*r + 12)^3/144115188075855872 – 1688849860263933/281474976710656)^2 + 1)^(3/2) + (12*((81*r)/1125899906842624 + 27/562949953421312)*((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 – (12*r + 12)^3/144115188075855872 – 1688849860263933/281474976710656)*((1111*r^9)/2500 – (1111*r^8)/2500 – (6667*r^7)/10000 + (6667*r^6)/10000 + r^5/4 – r^4/4 – (139*r^3)/5000 + (139*r^2)/5000))/(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 – (12*r + 12)^3/144115188075855872 – 1688849860263933/281474976710656)^2 + 1)^(1/2))^2/(1728*(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 – (12*r + 12)^3/144115188075855872 – 1688849860263933/281474976710656)^2 + 1)^(3/2))

Best Answer

I am not certain what the problem is.
To evaluate the ‘g’ function at the chosen value of ‘r’, try this:
syms r
g(r)=(12*(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 - (12*r + 12)^3/144115188075855872 - 1688849860263933/281474976710656)^2 + 1)^(1/2)*((15554*r^6)/625 - (19998*r^7)/625 + (140007*r^5)/5000 - (20001*r^4)/1000 - 5*r^3 + 3*r^2 + (417*r)/2500 - 139/2500) - (12*((27*r)/1125899906842624 - (9*(12*r + 12)^2)/36028797018963968 + 39/1125899906842624)^2*((1111*r^9)/2500 - (1111*r^8)/2500 - (6667*r^7)/10000 + (6667*r^6)/10000 + r^5/4 - r^4/4 - (139*r^3)/5000 + (139*r^2)/5000))/(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 - (12*r + 12)^3/144115188075855872 - 1688849860263933/281474976710656)^2 + 1)^(1/2) - (24*((27*r)/1125899906842624 - (9*(12*r + 12)^2)/36028797018963968 + 39/1125899906842624)*((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 - (12*r + 12)^3/144115188075855872 - 1688849860263933/281474976710656)*((9999*r^8)/2500 - (2222*r^7)/625 - (46669*r^6)/10000 + (20001*r^5)/5000 + (5*r^4)/4 - r^3 - (417*r^2)/5000 + (139*r)/2500))/(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 - (12*r + 12)^3/144115188075855872 - 1688849860263933/281474976710656)^2 + 1)^(1/2) + (12*((27*r)/1125899906842624 - (9*(12*r + 12)^2)/36028797018963968 + 39/1125899906842624)^2*((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 - (12*r + 12)^3/144115188075855872 - 1688849860263933/281474976710656)^2*((1111*r^9)/2500 - (1111*r^8)/2500 - (6667*r^7)/10000 + (6667*r^6)/10000 + r^5/4 - r^4/4 - (139*r^3)/5000 + (139*r^2)/5000))/(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 - (12*r + 12)^3/144115188075855872 - 1688849860263933/281474976710656)^2 + 1)^(3/2) + (12*((81*r)/1125899906842624 + 27/562949953421312)*((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 - (12*r + 12)^3/144115188075855872 - 1688849860263933/281474976710656)*((1111*r^9)/2500 - (1111*r^8)/2500 - (6667*r^7)/10000 + (6667*r^6)/10000 + r^5/4 - r^4/4 - (139*r^3)/5000 + (139*r^2)/5000))/(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 - (12*r + 12)^3/144115188075855872 - 1688849860263933/281474976710656)^2 + 1)^(1/2))^2/(1728*(((3*r)/281474976710656 + (3*(12*r + 12)^2)/36028797018963968 - (12*r + 12)^3/144115188075855872 - 1688849860263933/281474976710656)^2 + 1)^(3/2));
r = 0.538469810105683;
Result = vpa(g(r))
producing:
Result =
0.00014765654531859441862062868960765
If you want to use that number outside of the Symbolic Math Toolbox, use the double function:
Result = double(g(r))
producing:
Result =
1.476565453185944e-04
If you are doing something else, please be specific, and preferably post the code that is causing problems.