clc clear all; close all; xm=100; ym=100; x=0; y=0; sink.x=0.5*xm; %location of sink on x-axis sink.y=0.9*ym; %location of sink on y-axis n=100 %nodes P=0.1 ; %probability of cluster heads Eo=0.5; %initial energy ETX=50*0.000000001; %tx energy ERX=50*0.000000001; %rx energy Efs=10*0.000000000001; %free space loss Emp=0.0013*0.000000000001; %multi path loss %Data Aggregation Energy EDA=5*0.000000001; %compression energy a=1; %fraction of energy enhancment of advance nodes rmax=3000 %maximum number of rounds do=sqrt(Efs/Emp); %distance do is measured Et=0; %variable just use below A=0; for i=1:1:n S(i).xd=rand(1,1)*xm; %generates a random no. use to randomly distibutes nodes on x axis XR(i)=S(i).xd; S(i).yd=rand(1,1)*ym; %generates a random no. use to randomly distibutes nodes on y axis YR(i)=S(i).yd; S(i).G=0; %node is elegible to become cluster head talha=rand*a; S(i).E=Eo*(1+talha); E(i)= S(i).E; A=A+talha; Et=Et+E(i); %estimating total energy of the network %initially there are no cluster heads only nodes S(i).type='N'; figure(10) plot(S(i).xd,S(i).yd,'bo'); text(S(i).xd+1,S(i).yd-0.5,num2str(i)); title 'Node Deployment'; xlabel 'X-Coordinate(m)'; ylabel 'Y-Coordinate(m)'; hold on; end d1=0.765*xm/2; %distance between cluster head and base station K=sqrt(0.5*n*do/pi)*xm/d1^2; %optimal no. of cluster heads d2=xm/sqrt(2*pi*K); %distance between cluster members and cluster head Er=4000*(2*n*ETX+n*EDA+K*Emp*d1^4+n*Efs*d2^2); %energy desipated in a round S(n+1).xd=sink.x; %sink is a n+1 node, x-axis postion of a node S(n+1).yd=sink.y; %sink is a n+1 node, y-axis postion of a node countCHs=0; %variable, counts the cluster head cluster=1; %cluster is initialized as 1 flag_first_dead=0; %flag tells the first node dead flag_tenth_dead=0; %flag tells the 10th node dead flag_all_dead=0; %flag tells all nodes dead dead=0; %dead nodes count initialized to 0 first_dead=0; tenth_dead=0; all_dead=0; allive=n; %counter for bit transmitted to Bases Station and to Cluster Heads packets_TO_BS=0; packets_TO_CH=0; for r=0:1:rmax r if(mod(r, round(1/P) )==0) for i=1:1:n S(i).G=0; S(i).cl=0; end end Ea=Et*(1-r/rmax)/n; dead=0; for i=1:1:n if (S(i).E<=0) dead=dead+1; if (dead==1) if(flag_first_dead==0) first_dead=r; flag_first_dead=1; end end if(dead==0.1*n) if(flag_tenth_dead==0) tenth_dead=r; flag_tenth_dead=1; end end if(dead==n) if(flag_all_dead==0) all_dead=r; flag_all_dead=1; end end end if S(i).E>0 S(i).type='N'; end end
tcl = tiledlayout(2,3,'TileSpacing','compact'); nexttile plot(magic(5)) axis tight nexttile scatter(rand(1,10), rand(1,10), 90, lines(10)) box on nexttile([2,1]) imagesc(peaks(200)) nexttile([1,2]) histogram2(2*randn(1,1000), randn(1,1000), 'FaceColor', 'Flat') cb = colorbar(); cb.Layout.Tile = 'south'; title(tcl, 'Global title') xlabel(tcl, 'Global xlabel') ylabel(tcl, 'Global ylabel')
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.