what is the error in this program

4 views (last 30 days)
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

Accepted Answer

Stephen23
Stephen23 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,'-*')
untitled.png

More Answers (1)

Alex Mcaulley
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')

Community Treasure Hunt

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

Start Hunting!