How to calculate very large number by Matlab

11 visualizaciones (últimos 30 días)
Fatima Majeed
Fatima Majeed el 13 de Jun. de 2024
Respondida: Shubham el 11 de Sept. de 2024
I want to find S_1+S_2+S_3
  8 comentarios
Steven Lord
Steven Lord el 14 de Jun. de 2024
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 el 14 de Jun. de 2024
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|
\]

Iniciar sesión para comentar.

Respuestas (1)

Shubham
Shubham el 11 de Sept. de 2024
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.

Categorías

Más información sobre Formula Manipulation and Simplification en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by