n=1000; x=rand (1,n); %Generate Uniform Random Variable k=0:0.1:1; y=normpdf(k,mean(x),std(x));%Y=NORMPDF(X,MU=mean(x),SIGMA=std(x)) [N,h]=hist(x,15); %Get the information for the histogram N=N/(h(2)-h(1))/n;%Change bar height to make it correspond to the theoritical density bar(h,N,1,'w') %Bar function plot hold on plot (k,y) hold off xlabel ('X') ylabel ('f(x)-Uniform (0,1)')
Hasil Simulasi PDF dan Histogram Uniform(0,1) Random Variabel
b. Uniform (a,b) Random Variable Misal a= Matlab code :
n=1000; x=rand (1,n); %Generate Uniform Random Variable a=2;b=5; %Set Value for Uniform (a,b)=U(2,5) z=(b-a)*x+a; %Random Varible for U(2,5) mean =(a+b)/2; %Set Expexted Value s_dev=((b-a)/12)^0.5; %Set Deviation Standard k=0:0.1:5; y=normpdf(k,mean,s_dev); %Y = NORMPDF(X,MU=(a+b)/2,SIGMA=((b- a)/12)^0.5) [N,h]=hist(z,15); %Get the information for the histogram N=N/(h(2)-h(1))/n;%Change bar height to make it correspond to the theoritical density bar(h,N,1,'w') %Bar function plot hold on plot (k,y) hold off xlabel ('X') ylabel ('f(x)-Uniform (a,b)')
Hasil Simulasi PDF dan Histogram Uniform(0,1) Random Variabel
c. Gaussian(, ) Random Variabel Matlab code :
n=1000; x=randn(1,n); %Generate Random Variable m=1; %Mean = 1 sd=2; %Standard Deviation = 2 z=m+x*sd; %r.v value Gaussian with mean=1, Standard Deviation =2 k=-8:0.1:8; y=normpdf(k,m,sd); %Y = NORMPDF(X,MU,SIGMA) [N,h]=hist(z,15); %Get the information for the histogram N=N/(h(2)-h(1))/n; %Change bar height to make it correspond to the theoritical density bar(h,N,1,'w') %Bar function plot hold on plot (k,y) hold off xlabel ('X') ylabel ('f(x)-Gaussian (1,2)')
Hasil Simulasi PDF dan Histogram Gaussian(,)Random Variabel = 1, =2
d. Rayleigh (a) Random Variabel Matlab Code :
n=1000; x=randn(1,n); %Generate Uniform Random Variable x y=randn(1,n); %Generate Uniform Random Variable y z = (x + j*y); % complex random variable
% probability density function of abs(z) zNum = [0:0.01:7]; sigma2 = 1; pz = (zBin/sigma2).*exp(-(zNum.^2)/(2*sigma2)); % pdf theory [N h] = hist(abs(z),15); % simulation N=N/(h(2)-h(1))/n;%Change bar height to make it correspond to the theoritical density bar(h,N,1,'w') %Bar function plot hold on plot(zNum,pz,'k') hold off xlabel('z'); ylabel('probability density, p(z)'); title('Probability density function of abs(z)' ) axis([0 7 0 0.7]);
Hasil Simulasi PDF dan Histogram Rayleigh Random Variabel
e. Eksponensial() Random Variabel Matlab Code :
n=1000; lamda =2; rv=rand(1,n); %Generate Random Variable X=-log(rv)/lamda; l=0:0.1:5; %axis value y=exppdf(l,1/2); %Y = EXPPDF(X,MU=1/2), pdf exponensial [N,h]=hist(X,20); %Get the information for the histogram N=N/(h(2)-h(1))/n; %Change bar height to make it correspond to the theoritical density plot (l,y) hold on bar(h,N,1,'w') %Bar function plot hold off xlabel ('X') ylabel ('f(x)-Exponensial ')
Hasil Simulasi PDF dan Histogram Rayleigh Random Variabel
f. Erlang(n,) Random Variabel Matlab Code k=1000; n=3; lamda=2; rv=rand(n,k); %Generate Random Variable LogU=-log(rv)/lamda; X=sum(LogU); [N,h]=hist(X,15); %Get the information for the histogram N=N/(h(2)-h(1))/k; %Change bar height to make it correspond to the theoritical density x=0:0.1:6; y=gampdf(x,n,1/lamda); %Erlang is the same with gamma pdf %y=((lamda^n)/factorial(n))*(x.^(n-1)).*exp(-lamda*x); bar(h,N,1,'w') hold on plot (x,y,'k') hold off xlabel ('X') ylabel ('f(x)-Erlang ')
Hasil Simulasi PDF dan Histogram Rayleigh Random Variabel
Solusi no 2. 1. Random Walk Berbagai kemungkinan arah pergerakan dari Model Random Walk
Matlab Code
r=[0 0]; % Initial condition for t= 0:0.1:60 % Setting for t= 1 minutes, Time Step = 0.1 X1=rand(1,2); % Generate random number X=X1>0.5; % Set Value <0.5 =0 and >0.5=1 if X==1 rnew=r+[1 0]; %X+ Direction elseif X(1)==1 rnew=r+[0 1]; %Y+ Direction elseif X(2)==1 rnew=r+[-1 0]; %X- Direction else rnew=r+[0 -1]; %Y- Direction end
hold on; plot([r(1) rnew(1)],[r(2) rnew(2)]); %get animation drawnow ; r=rnew; %Update position end
Hasil Simulasi :
Model pergerakan Random Walk yang lain : Matlab Code : K=1000; %1000 step r=1; u=19; X=[0 0]; %Posisi awal for n=1:K s=ceil(u*rand); %Generate untuk posisi acak Z=X(n,:)+r*[cos(2*pi*s/u) sin(2*pi*s/u)]; %Setting sudut pergerakan X=[X;Z]; end plot(X(:,1), X(:,2)) hold on plot(0,0,'o') hold off axis equal
Hasil Simulasi :
2. Random waypoint: Posisi awal Random Way Point Model
Matlab Code : clear all; s_input = struct('V_POSITION_X_INTERVAL',[10 30],...%(m) 'V_POSITION_Y_INTERVAL',[10 30],...%(m) 'V_SPEED_INTERVAL',[0.2 2.2],...%(m/s) 'V_PAUSE_INTERVAL',[0 1],...%pause time (s) 'V_WALK_INTERVAL',[2.00 6.00],...%walk time (s) 'V_DIRECTION_INTERVAL',[-180 180],...%(degrees) 'SIMULATION_TIME',500,...%(s) 'NB_NODES',20); s_mobility = mobility(s_input); %Use function : mobility timeStep = 0.1;%(s) animasi(s_mobility,s_input,timeStep); %Draw animation, use function : animasi
Fungsi mobility.m
function s_mobility = mobility(s_input) %The Random Waypoint mobility model. global s_mobility_tmp; global nodeIndex_tmp;
s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE(end+1,1) = 0; s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_IS_MOVING(end+1,1) = false; s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DURATION(end+1,1) = Out_adjustDuration_random_waypoint(s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_ TIME(end),unifrnd(s_input.V_PAUSE_INTERVAL(1),s_input.V_PAUSE_INTERVAL(2)), s_input); end end %To have speed vectors as well rather than %only the scalar value: nb_speed = length(s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE); s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_X = zeros(nb_speed,1); s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_Y = zeros(nb_speed,1); for s = 1:nb_speed speed = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_MAGNITUDE(s); direction = s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_DIRECTION(s); s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_X(s) = speed*cosd(direction); s_mobility_tmp.VS_NODE(nodeIndex_tmp).V_SPEED_Y(s) = speed*sind(direction); end
function duration = Out_adjustDuration_random_waypoint(time,duration,s_input)
if ((time+duration) >= s_input.SIMULATION_TIME) duration = s_input.SIMULATION_TIME - time; end end
Fungsi animasi.m function animasi(s_mobility,s_input,time_step)
v_t = 0:time_step:s_input.SIMULATION_TIME; %setting time
for nodeIndex = 1:s_mobility.NB_NODES %Get position use linear interpolation vs_node(nodeIndex).v_x = interp1(s_mobility.VS_NODE(nodeIndex).V_TIME,s_mobility.VS_NODE(nodeIndex). V_POSITION_X,v_t); vs_node(nodeIndex).v_y = interp1(s_mobility.VS_NODE(nodeIndex).V_TIME,s_mobility.VS_NODE(nodeIndex). V_POSITION_Y,v_t); end
figure; hold on; for nodeIndex = 1:s_mobility.NB_NODES vh_node_pos(nodeIndex) = plot(vs_node(nodeIndex).v_x(1),vs_node(nodeIndex).v_y(1),'*','color',[0.3 0.3 1]); end title(cat(2,'Simulation time (sec): ',num2str(s_mobility.SIMULATION_TIME))); xlabel('X (meters)'); ylabel('Y (meters)'); title('Radom Waypoint mobility'); ht = text(min(vs_node(1).v_x),max(vs_node(1).v_y),cat(2,'Time (sec) = 0')); axis([min(vs_node(1).v_x) max(vs_node(1).v_x) min(vs_node(1).v_y) max(vs_node(1).v_y)]); hold off; for timeIndex = 1:length(v_t); t = v_t(timeIndex); set(ht,'String',cat(2,'Time (sec) = ',num2str(t,4))); for nodeIndex = 1:s_mobility.NB_NODES
set(vh_node_pos(nodeIndex),'XData',vs_node(nodeIndex).v_x(timeIndex),'YData ',vs_node(nodeIndex).v_y(timeIndex)); end drawnow; end end
Hasil Simulasi :
Jawaban pertanyaan : Beberapa pemodelan gerakan di atas diambil karena pengguna dapat berada dimana saja dan dengan gerakan yang tidak dapat diprediksi sehingga dilakukan pemodelan. Disamping itu, pemodelan pada keadaan tertentu dimana terdapat banyak interferensi seperti di dalam kendaraan (di jalan raya,pegunungan, hutan, lapangan), di dalam bangunan, di kerumunan orang atau di tempat yang padat penduduknya dengan distribusi dan penyebaran yang beragam sehingga dilakukan pemodelan.