Advertisement
Guest User

get_next_state.m

a guest
Nov 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.67 KB | None | 0 0
  1. function next_state = get_next_state(L, curr_state)
  2. % Получение следующего состояния из текущего используя матрицу переходных интенсивностей
  3.     next_state = curr_state;
  4.     next_possible_states = [1:curr_state-1, curr_state+1:length(L)];
  5.     probability = L(curr_state, next_possible_states) ./ (-L(curr_state, curr_state));
  6.     rand_number = rand;
  7.     prefix_sum = 0;
  8.     for i = 1:length(probability)
  9.         prefix_sum += probability(i);
  10.         if (rand_number <= prefix_sum)
  11.             next_state = next_possible_states(i);
  12.             break;
  13.         end
  14.     end
  15.     if (next_state == curr_state), printf('Error: can not get next state\n'); end;
  16. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement