필터 지우기
필터 지우기

Matlab showing 0 instead of small value

조회 수: 1 (최근 30일)
Ismita
Ismita 2024년 3월 23일
댓글: Sam Chak 2024년 3월 23일
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_rho_m = 24x1
1.0e-25 * -0.0844 -0.0372 -0.0310 -0.0436 -0.0454 0.0288 -0.0247 -0.0228 -0.0316 -0.0064
delta_p_m = pressure_CGS - mean (pressure_CGS) % \delta p_m i.e. fluctuation in pressure
delta_p_m = 24x1
0 0 0 0 0 0 0 0 0 0
%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)
ans = 24x1
1.0e-14 * -0.0927 -0.0092 -0.1341 0.0340 -0.1948 0.2477 0.2828 0.2249 0.1063 0.0416

답변 (1개)

Sam Chak
Sam Chak 2024년 3월 23일
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
Ismita
Ismita 2024년 3월 23일
thank you
Sam Chak
Sam Chak 2024년 3월 23일
You are welcome, @Ismita. If you find the explanation helpful, please consider clicking 'Accept' ✔ on the answer to close the issue.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by