Octave if when loop problem
Mostrar comentarios más antiguos
Hi
I'm trying to program an exponential distibution with Octave. I want to save the values for x and s. My two problems are that the loop stops as soon as even one of the s(j) is >30, instead of when all of them are. And that when I write y(j)=rand(1), it gives me a matrix full of the same random number, but I want 30 different random numbers. When I write y=rand(30,1), then I get an error saying the the dimentions are 1x1 and 1x30 and that they don't match.
function[x,w]=wartezeitExp4(t,lambda)
n=10;
t=30;
lambda=4;
y=0;
s=0;
x=0;
while s<t
s=s+1
for j=1:30
x(j)=(log(1-rand(30,1))./(-lambda));
s(j)=s+x;
endfor
disp (t)
end
end
3 comentarios
David Hill
el 14 de En. de 2021
I do not understand what you are trying to do. What is 's' suppose to be? Every iteration of your while loop you are over writing your variables x and s.
Verity Rothermel
el 14 de En. de 2021
Rik
el 14 de En. de 2021
Why don't you write a function that will run your expirement once and return the relevant variables. Then you can easily run that in a loop to do 1000 experiments.
Als a side-note: please make sure your question applies to Matlab as well. This site is maintained by Mathworks and it would be in poor taste to repay that kindness by providing a solution that will only work on Octave. There is no harm in making sure the code works on both platforms (I actively confirm that for my FEX submissions), but my personal line is that it should at least run on Matlab as well. Your interpretation of the terms of service might be different.
Respuestas (0)
Categorías
Más información sobre Octave en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!