How to calculate very large number by Matlab

I want to find S_1+S_2+S_3

8 Commenti

Please supply the above graphics as code or at least as a plain ascii text so that we don't need to type it again.
Replaced with larger image.
@Fatima Majeed Have you written any code for this yet?
% Given values
H = 3000175332800;
D = 0.9999932;
x = exp(2.8 * 10^10);
C_1 = 17.362;
C_2 = 2.077;
B_2 = 0.18525;
% 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);
% Display the result
fprintf('The value of b is: %.6f\n', b);
The value of b is: NaN
x = exp(2.8 * 10^10);
The above will lead to inf.....Are you sure you want that?
Fatima Majeed
Fatima Majeed il 14 Giu 2024
Modificato: Fatima Majeed il 14 Giu 2024
yeh, I want to calculate in the end the value of S_1+S_2+S_3.But my problem is with that also with the value of H
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.
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|
\]

Accedi per commentare.

Risposte (1)

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.

Categorie

Prodotti

Richiesto:

il 13 Giu 2024

Risposto:

il 11 Set 2024

Community Treasure Hunt

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

Start Hunting!

Translated by