# what is the error in this program

1 view (last 30 days)
sanjiv kumar on 5 Sep 2019
Commented: sanjiv kumar on 5 Sep 2019
for k=5:5:50
z=zeros(1,length(k));
Pr1=(10*0.75*0.75*(exp(-0.984*k/cos(pi/36)))*0.01*cos(pi/36)/((2*pi*k.^2)*(1-cos(pi/3))));
%Pr_dbm1(k)=10*log10(Pr1)
z(k)=10*log10(Pr1);
plot(k,z)
xlabel('distance')
ylabel('Power')
title('Rcvd Power vs Distance')
%Pr1
end

Stephen Cobeldick on 5 Sep 2019
k = 5:5:50;
Pr1 = (10*0.75*0.75*(exp(-0.984*k./cos(pi/36))) .* 0.01 .* cos(pi/36) ./ ((2*pi*k.^2)*(1-cos(pi/3))));
z=10.*log10(Pr1);
plot(k,z,'-*')

#### 1 Comment

sanjiv kumar on 5 Sep 2019
thank you for helping me............

Alex Mcaulley on 5 Sep 2019
There is no error in your code, the problem is that it doesn't do whatt you want. I guess you want something like this (without loops):
k=5:5:50;
Pr1=(10*0.75*0.75*(exp(-0.984*k/cos(pi/36)))*0.01*cos(pi/36)./((2*pi*k.^2)*(1-cos(pi/3))));
%Pr_dbm1(k)=10*log10(Pr1)
z=10*log10(Pr1);
plot(k,z)
xlabel('distance')
ylabel('Power')
title('Rcvd Power vs Distance')