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 1105089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:34:36+00:00 2026-05-17T01:34:36+00:00

I am rewriting a Monte Carlo simulation model in MATLAB with an emphasis on

  • 0

I am rewriting a Monte Carlo simulation model in MATLAB with an emphasis on readability. The model involves many particles, represented as (x,y,z), following a random walk over a small set of states with certain termination probabilities. The information relevant for output is the number of particles that terminate in a given state.

The simulation requires enough particles that running it for each particle individually is cost prohibitive. Vectorization seems to be the way to get performance out of MATLAB, but is there any idiomatic way of creating a vectorized version of this simulation in MATLAB?

I’m beating my head against the wall to accomplish this – I’ve even tried creating a (nStates x nParticles) matrix representing each particle-state combination, but this approach quickly spirals out of control in terms of readability since particles bounce from state to state independently of one another. Should I just bite the bullet and switch to a language more suitable for this?

  • 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-17T01:34:37+00:00Added an answer on May 17, 2026 at 1:34 am

    Just write the code as you normally would. Almost all matlab functions can accept and return vectorized input. For instance, to simulate a brownian motion of N particles in 1 dimension

    position = zeros([N 1]); %start at origin
    sigma = sqrt(D * dt); %D is diffusion coefficient, dt is time step
    for j = 1:numSteps
        position = position + sigma*randn(size(position));
    end
    

    if you wanted to have a different sigma for each position, you would make sigma a vector the same size as position and use “dot times” notation to indicate element by element operation

    position = position + sigma.*randn(size(position));
    

    if the scattering was an arbitrary function of position and some random element, you would just have to write a vectorized function, e.g.

    function newstep = step(position)
    %diffusion in a overdamped harmonic potential
    newstep = -dt*k*position + D*randn(size(position));
    
    for j = 1:numsteps; position = position + step(position);
    

    and so on

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After rewriting my event invocation function to handle the events and their arguments generically,
I'm rewriting some messy code that manages a database, and saw that the original
I'm rewriting an application so that we can stop using the old Microsoft.Web.Services2.Security.X509 from
I just finished rewriting a significant portion of my web site using python's django,
I am currently rewriting one of my programs. It has a heavily recursive function
We're rewriting a website used by one of our clients. The user traffic on
I'm using URL rewriting with my APS.NET application and haven't had much luck matching
I have URL rewriting in my asp.net web solution defined how can I set
I currently have one server with nginx that reverse_proxy to apache (same server) for
I have some troubles re-writing this query to using joins instead of the two

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.