From: Dharini Pathmanathan on
Please help!
This is part of my script.

pb=[];
pb(1)=exp(-lam)

for k=1:n
pb(k+1)=(lam/k)*pb(k)
end

I want the values of pb to always be between 0 and 1. How do I specify this in my program?
Thank you.
From: Roger Stafford on
"Dharini Pathmanathan" <dharen10(a)gmail.com> wrote in message <hvulnk$4uf$1(a)fred.mathworks.com>...
> Please help!
> This is part of my script.
>
> pb=[];
> pb(1)=exp(-lam)
>
> for k=1:n
> pb(k+1)=(lam/k)*pb(k)
> end
>
> I want the values of pb to always be between 0 and 1. How do I specify this in my program?
> Thank you.
- - - - - - - - -
Provided that lam is positive, all the pb values should lie in (0,1). What you are asking is that

pb(k+1) = lam^k/k!*exp(-lam) always lies in (0,1) for all k.

This is equivalent to

lam^k/k! < exp(lam) = 1 + lam/1! + lam^2/2! + lam^3/3! + ...

which is clearly always true for positive lam.

Request: Please don't enter duplicate threads. It is an inconvenience to those who are responding because it often causes an unnecessary duplication of their efforts.

Roger Stafford
From: darthshak on
You could divide all elements by the largest value.
From: Roger Stafford on
darthshak <vishakadatta(a)gmail.com> wrote in message <1451346959.59803.1278071836993.JavaMail.root(a)gallium.mathforum.org>...
> You could divide all elements by the largest value.
- - - - - - - - -
That is not necessary, Darthshak. None of the elements in pb can ever exceed or even become as large as 1. See the argument in the duplicate thread

http://www.mathworks.com/matlabcentral/newsreader/view_thread/285332

Roger Stafford