Octave if when loop problem
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Rik
am 14 Jan. 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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Octave finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!