- #1
galanos
- 2
- 0
Im trying to build a Matlab code for the distribution of a parameter (such as density or temperature) in 3D, then visualise the distribution also in 3D. At the end, the distribution plot should look like a cone shape where the highest value for the density (or temperature) is at the tip of the cone and lower values as moving down and outwards on the cone. So that density should decrease both by horizontal and vertical distance from the cone tip. I've tried Normal (Gausian) distribution for the 2D case and it worked but i don't know how to apply that for 3D case and I am really lost!
What I am intended to do is to use many equally sized cells (cubes) to define a 3D environment (volume) and then assign values for the density to each of these cells according to a distribution function (normal dist func.)
Here is what I've tried so far for the 2D case. You may see several funny mistakes since I am almost a beginner on Matlab! Please give me some idea and light up my world!
% Standard Normal Distribution of Density
clear all,close all
% Parameters:
% x:cell number
% l: total length of cells in a layer
% h: distance from the cone tip
% d_cell: dimension of the cell
% i: layer number
% m: mass in each layer (constant)
theta = pi/10; % cone angle (18 deg)
d_cell = 0.1; % cell dimension
cell_volume = d_cell^3;
mu = 0; % mean value of the normal distribution
m = 0.005; %row mass
symvar h; % symbolic variable
h = 1:60;
l = 2*h*tan(theta/2);
% plot(h,l(h));
% number of cells in each layer:-----------------------------------------
n = l/d_cell;
n = fix((n(h)+1)/2)*2-1; % rounds to the nearest smaller odd number
% standard deviation of the density distribution:------------------------
sigma = [];
sigma(1) = 1;
for j = 2:60
sigma(j) = sigma(j-1)*(n(j)/n(j-1));
end
% normal distribution of density on each layer:--------------------------
x = cell(60,1);
y = cell(60,1);
N = cell(60,1);
coef = cell(60,1);
for i = 1:60
t = (n(i)-1)/2;
x{i,1} = 1:t;
y{i,1} = (exp(-(x{i,1}-mu).^2/(2*(sigma(i)).^2)))./(sigma(i)*sqrt(2*pi));
N{i,1} = y{i,1}/max(y{i,1});
coef{i,1} = m/sum(cell_volume*N{i,1});
N{i,1} = coef{i,1}*N{i,1};
end
plot(x{i,1},N{i,1});
Thanks in advance for any help..
What I am intended to do is to use many equally sized cells (cubes) to define a 3D environment (volume) and then assign values for the density to each of these cells according to a distribution function (normal dist func.)
Here is what I've tried so far for the 2D case. You may see several funny mistakes since I am almost a beginner on Matlab! Please give me some idea and light up my world!
% Standard Normal Distribution of Density
clear all,close all
% Parameters:
% x:cell number
% l: total length of cells in a layer
% h: distance from the cone tip
% d_cell: dimension of the cell
% i: layer number
% m: mass in each layer (constant)
theta = pi/10; % cone angle (18 deg)
d_cell = 0.1; % cell dimension
cell_volume = d_cell^3;
mu = 0; % mean value of the normal distribution
m = 0.005; %row mass
symvar h; % symbolic variable
h = 1:60;
l = 2*h*tan(theta/2);
% plot(h,l(h));
% number of cells in each layer:-----------------------------------------
n = l/d_cell;
n = fix((n(h)+1)/2)*2-1; % rounds to the nearest smaller odd number
% standard deviation of the density distribution:------------------------
sigma = [];
sigma(1) = 1;
for j = 2:60
sigma(j) = sigma(j-1)*(n(j)/n(j-1));
end
% normal distribution of density on each layer:--------------------------
x = cell(60,1);
y = cell(60,1);
N = cell(60,1);
coef = cell(60,1);
for i = 1:60
t = (n(i)-1)/2;
x{i,1} = 1:t;
y{i,1} = (exp(-(x{i,1}-mu).^2/(2*(sigma(i)).^2)))./(sigma(i)*sqrt(2*pi));
N{i,1} = y{i,1}/max(y{i,1});
coef{i,1} = m/sum(cell_volume*N{i,1});
N{i,1} = coef{i,1}*N{i,1};
end
plot(x{i,1},N{i,1});
Thanks in advance for any help..