Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7699357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:27:32+00:00 2026-05-31T22:27:32+00:00

Lets say I want to simulate a particle state, which can be normal (0)

  • 0

Lets say I want to simulate a particle state, which can be normal (0) or excited (1) in given frame. The particle is in excited state f % of time. If the particle is in excited state, it lasts for ~L frames (with poisson distribution). I want to simulate that state for N time points. So the input is for example:

N = 1000;
f = 0.3;
L = 5;

and the result will be something like

state(1:N) = [0 0 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 ... and so on]

with sum(state)/N close to 0.3

How to do that?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:27:33+00:00Added an answer on May 31, 2026 at 10:27 pm
    %% parameters
    f = 0.3; % probability of state 1
    L1 = 5;  % average time in state 1
    N = 1e4;
    s0 = 1; % init. state
    %% run simulation
    L0 = L1 * (1 / f - 1); % average time state 0 lasts
    p01 = 1 / L0; % probability to switch from 0 to 1
    p10 = 1 / L1; % probability to switch from 1 to 0
    p00 = 1 - p01;
    p11 = 1 - p10;
    sm = [p00, p01; p10, p11];  % build stochastic matrix (state machine)
    bins = [0, 1]; % possible states
    states = zeros(N, 1);
    assert(all(sum(sm, 2) == 1), 'not a stochastic matrix');
    smc = cumsum(sm, 2); % cummulative matrix
    xi = find(bins == s0);
    for k = 1 : N
        yi = find(smc(xi, :) > rand, 1, 'first');
        states(k) = bins(yi);
        xi = yi;
    end
    %% check result
    ds = [states(1); diff(states)];
    idx_begin = find(ds == 1 & states == 1);
    idx_end = find(ds == -1 & states == 0);
    if idx_end(end) < idx_begin(end)
        idx_end = [idx_end; N + 1];
    end
    df = idx_end - idx_begin;
    fprintf('prob(state = 1) = %g; avg. time(state = 1) = %g\n', sum(states) / N, mean(df));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I want to implement a smart pointer a_ptr which can be compared
Lets say I have a single object of type Car which I want to
Let's say I've got a window for which I want to simulate a mouse
Lets say you want to write a high performance method which processes a large
Lets say I want to add an extension method to class B. Can I
Lets say you want to create a listing of widgets The Widget Manufacturers all
Lets say I want to define 2 styles. .color_red { color: Red; } .banner
Lets say we want a library of javascript-based pieces of functionality (I'm thinking jquery):
Lets say I want to make few classes to determine behaviour of agents. The
I would appreciate any help on this issue. Lets say I want to load

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.