How to calculate very large number by Matlab

조회 수: 13 (최근 30일)
Fatima Majeed
Fatima Majeed 2024년 6월 13일
답변: Shubham 2024년 9월 11일
I want to find S_1+S_2+S_3
  댓글 수: 8
Steven Lord
Steven Lord 2024년 6월 14일
Even if you try to operate on this symbolically, it's extremely large.
x = exp(sym(2.8e10))
x = 
vpa(x, 10)
ans = 
numberOfDigits = vpa(log10(x))
numberOfDigits = 
12160245493.291051174231609729665
If you were able to write out x it would have over twelve billion digits.
What's the purpose of this calculation? What does S1+S2+S3 represent? I'd consider trying to find another way to compute that quantity that doesn't require combining numbers that vary by so so many orders of magnitude.
Fatima Majeed
Fatima Majeed 2024년 6월 14일
I am reading this paper https://doi.org/10.48550/arXiv.2204.01980 on the page 13 he wanted to calculate A(x,delta) to bound
\[
\left| \frac{\psi(x) - x}{x} \right|
\]

댓글을 달려면 로그인하십시오.

답변 (1개)

Shubham
Shubham 2024년 9월 11일
Hi Fatima,
To calculate very large numbers in MATLAB, especially when dealing with exponential functions that can result in overflow, you can use "syms" method of computation. Here's a refined approach to handle your calculation:
% Use symbolic variables for large computations
syms H D C_1 C_2 B_2 x
% Given values
H_val = 3000175332800;
D_val = 0.9999932;
C_1_val = 17.362;
C_2_val = 2.077;
B_2_val = 0.18525;
% Assign values to symbolic variables
H = sym(H_val);
D = sym(D_val);
C_1 = sym(C_1_val);
C_2 = sym(C_2_val);
B_2 = sym(B_2_val);
x = exp(sym(2.8 * 10^10)); % Handle large exponentials symbolically
% Calculations
R = (log(x))^(3/5) / (log(log(x)))^(1/5);
S_1 = x^(-0.5) * (log(H / (2 * pi)))^2 / (2 * pi) + x^(D - 1) * ((B_2 * R - log(2))^2 / (2 * pi) - (log(H / (2 * pi)))^2 / (2 * pi) + 2.394);
S_2 = 2 * (C_1 * exp(B_2 * (5 - 8 * D) * R / 3) * (B_2 * R)^(5 - 2 * D) + C_2 * exp(-B_2 * R) * (B_2 * R)^2);
S_3 = 1.197 * log(x) / (B_2 * R);
b = (exp(B_2 * (5 - 8 * D) * R / 3) * (B_2 * R)^(5 - 2 * D))^(-1) * (S_1 + S_2 + S_3);
% Evaluate the result with a specified precision
b_value = vpa(b, 10); % Specify the desired precision
fprintf('The value of b is: %s\n', b_value);
The value of b is: 1.3775207604614539285095203023078e+78982
By using symbolic variables, you can avoid overflow and manage large numbers more effectively. Use "vpa" to specify the precision for the final result, which helps in managing large numbers.
Refer to the following documentation links for more information:
Hope this helps.

카테고리

Help CenterFile Exchange에서 Digital Filtering에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by