Help with basic code
Mostrar comentarios más antiguos
I attached the pdf its the last page 9 I meant to code that in MATLAB, I believe even the code is basic but I am not sure why is not working. I tried to change the code several time but no luck.
from the Paper:
(1) t = 0, I = 0.
(2) Generate a random number U ~ U(0, 1).
(3) t = t - (1/Lam)*ln(U). If t > T then stop.
(4) Generate a random number U ~ U(0, 1).
(5) If U <= Lam(t)/Lam, set I = I + 1, S(I) = t.
(6) Go to step 2.
Output:
I: the number of events at time T ,
S(1), . . . , S(I): the event times.
2. Direct generation of successive event times
function nonhomogeneous (i,s)
i = 0;
t = 010;
T = length(cos(t));
s = [0,t];
u = rand (1,1);
t = t - (1 /cos(t)*log(u));
while t <= T
u2 = rand (1,1);
if ( u2 <= cos(t) / max(cos(t)))
hold on
plot(t,cos(t))
i = i+1;
s(i)=t;
u = rand (1,1);
t = t - (1 /cos(t)*log(u));
end
end
Respuesta aceptada
Más respuestas (2)
Andrew Newell
el 22 de Mzo. de 2011
@Susan, thank you for formatting the code nicely. I wish more people would in their questions!
I notice your function doesn't have any outputs and your inputs are redundant. If you change the top line to
function [s,i] = nonhomogeneous
do you get what you want?
EDIT: I see several problems:
t = 010; % t=10
instead of
t = 0;
Also,
T = length(cos(t));
gives T=1 (is that what you're after?)
s = [0,t];
initializes your array s to [0 10] instead of [].
Yet another: there is no lambda. Instead, you're using
max(cos(t))
which is only the maximum for the current values of t, not 1 as it should be.
1 comentario
Susan
el 22 de Mzo. de 2011
Jan Jensen
el 22 de Mzo. de 2011
0 votos
I've read the presentation, and it was quite interesting. Not sure I understand all the implications, though.
Please post your definition of the lambda function as well as the code.
A good starting point could also be to implement the simulation of Poisson process with constant decay (lambda = constant). The one on slide 5. The dimensions of the output variable S should be the same. If the plot of S for lambda=constant makes sense you have made a great step forward in debugging your code, including your plotting commands :)
1 comentario
Susan
el 22 de Mzo. de 2011
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!