Matlab showing 0 instead of small value
2 views (last 30 days)
Show older comments
In the following code delta_rho_m, delta_p_m (=(mass_density_CGS - mean(mass_density_CGS))) are very small, and delta_p_m is showing as 0 for all the data, at the same time (mass_density_CGS - mean(mass_density_CGS)) is giving values. I request for help to solve this issue
clc;
clear; % all;
data = load('NH_VOY2_Data.txt');
% data = load('UxUyUz.txt');
mp = 1.67*10^(-24); %proton mass gm
mp_SI = 1.67*10^(-27); %proton mass kg
cc_m3 = 10^(-6); % m^3
k = 1.3807 * 10^(-16); % Boltzmann constant in CGS cm2 g s-2 K-1
% k = 1.380649*10^(-23); % boltzmann constant SI J/K
gamma = 5.00/3.00; %
time = data(:, 1);
density_CGS = data(:, 2);
speed_km = data(:, 3); %
temperature = data(:, 4);
distance = data(:, 5);
latitude = data(:, 6);
longitude = data(:, 7);
pressure_CGS = zeros(size(density_CGS)); %pressure_SI = zeros(size(density));
speed_R = zeros(size(speed_km));
speed_T = zeros(size(speed_km));
speed_N = zeros(size(speed_km));
speed = zeros(size(speed_km));
%distance_sun = zeros(size(speed));
%for i = 1:length(density_CGS)
mass_density_CGS = density_CGS * mp; %\rho
delta_rho_m = mass_density_CGS - mean(mass_density_CGS) % \delta \rho_m i.e. fluctuation in mass density
delta_p_m = pressure_CGS - mean (pressure_CGS) % \delta p_m i.e. fluctuation in pressure
%speed_SI(i) = speed_km(i) * 1000.00; % SI unit from km to m
%end
for i = 1:length(speed_km)
speed_R(i) = speed_km(i) * cosd(latitude(i)) * cosd(longitude(i));
speed_T(i) = speed_R(i) * tand(longitude(i));
speed_N(i) = speed_km(i) * sind(latitude(i));
speed(i) = sqrt(speed_R(i)^2 + speed_T(i)^2 + speed_N(i)^2);
pressure_CGS(i) = density_CGS(i) * k * temperature(i); % P = nkT but here it is \rho kT; need to check
end
mean_mass_density = mean(mass_density_CGS); %\rho_0 as r_0
mean_pressure_CGS = mean(pressure_CGS); % p_0
rho_0 = mean_mass_density;
P_0 = mean_pressure_CGS;
a_0 = sqrt((gamma*P_0)/rho_0); % sound speed
% a_02 = a_0^2;% (a_0)^2
pressure_CGS - mean (pressure_CGS)
0 Comments
Answers (1)
Sam Chak
on 23 Mar 2024
Hi @Ismita
When examining the flow of execution, you will notice that the 'pressure_CGS' vector is initialized with twenty-four zeros. Consequently, calculating the average of the elements in the vector will yield zero as the result. Therefore, subtracting zero from zero will also result in zero. This occurs prior to the computation within the for-loop.
pressure_CGS = zeros(size(density_CGS));
...
delta_p_m = pressure_CGS - mean(pressure_CGS) % \delta p_m i.e. fluctuation in pressure
2 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!