geometric rv code user defined function

15 views (last 30 days)
Anjali
Anjali on 26 Jan 2024
Edited: Torsten on 26 Jan 2024
I tried to code geometric rv pdf but it's giving accurate result for p=0.5 onlyl
Here, is the code
t=1:10;
p=0.95;
f=geometric_rv(t, p);
z=pdf('geo', t, p);
figure;
plot(f);
hold on;
stem(z);
legend('User-defined', 'system in-built');
hold off;
function f=geometric_rv(t, p)
f=(1-p)*p.^(t);
end

Answers (1)

Torsten
Torsten on 26 Jan 2024
Edited: Torsten on 26 Jan 2024
t=0:10;
p=0.95;
f=geometric_rv(t, p)
f = 1×11
0.9500 0.0475 0.0024 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
z=pdf('Geo', t, p)
z = 1×11
0.9500 0.0475 0.0024 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
figure;
plot(f);
hold on;
stem(z);
legend('User-defined', 'system in-built');
hold off;
function f=geometric_rv(t, p)
f=p*(1-p).^t;
end

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!