Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function next_state = get_next_state(L, curr_state)
- % Получение следующего состояния из текущего используя матрицу переходных интенсивностей
- next_state = curr_state;
- next_possible_states = [1:curr_state-1, curr_state+1:length(L)];
- probability = L(curr_state, next_possible_states) ./ (-L(curr_state, curr_state));
- rand_number = rand;
- prefix_sum = 0;
- for i = 1:length(probability)
- prefix_sum += probability(i);
- if (rand_number <= prefix_sum)
- next_state = next_possible_states(i);
- break;
- end
- end
- if (next_state == curr_state), printf('Error: can not get next state\n'); end;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement