Questions tagged [simulation]

Simulation is the imitation of some real thing, state of affairs, or process. The act of simulating something generally entails representing certain key characteristics or behaviours of a selected physical or abstract system.

28 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5 votes
0 answers
175 views

Fast Hardy-Weinberg equilibrium simulation

I was very bored over one of my breaks this year, so I built a Hardy-Weinberg equilibrium simulator for two unrelated alleles of the same gene. Hardy-Weinberg equilibrium is when there is no evolution,...
computergorl's user avatar
5 votes
0 answers
792 views

Customizable Multi-Agent Predator/Prey Simulation

I am trying to create a highly customizable "battle simulator". The default setup is a predator/prey relationship (no births); however, I am trying to create code such that it's easy to add and ...
Swerve's user avatar
  • 51
4 votes
0 answers
2k views

Monte Carlo simulation to price an Option in Python

In what ways can I make this code more efficient? I haven't put in comments and descriptions yet. I need to do that. Ideally, I'd like to make the S, v, r, and K user entered as I did with T. I'm ...
DudeWah's user avatar
  • 161
4 votes
0 answers
2k views

Satellite orbit simulation in Matlab using Runge Kutta 4

I have a satellite orbit simulation in Matlab (Using Runge Kutta 4). It seems ugly and I don't know how to fix it. fx.m file: function v = fx(t,x,vx) v = vx; ...
tanpham's user avatar
  • 41
4 votes
0 answers
621 views

Speed up a monte carlo simulation with nested loop

I would like to know if there is a more efficiency way to speed up below code. It uses a procedure where subsampling is required in the nested loop (which a previous answer helped to make more ...
barryq's user avatar
  • 141
3 votes
0 answers
71 views

Finds a moving target within a given space

https://youtu.be/XEt09iK8IXs?t=1264 Ben Awad did a mock interview with a React developer, and asked this question. There are a set of 100 holes (0-99). A rabbit is located in one of these holes. Every ...
Stephen Williams's user avatar
3 votes
0 answers
34 views

MatLab: Plotting Output Electric Field Spectrum

Goal This code combines two matrices, diagonalizes that matrix, and finds the right and left eigenvectors, right and left eigenvectors are normalized with respect to each other, then it is multiplied ...
Mate's user avatar
  • 31
3 votes
0 answers
75 views

Monte Carlo Simulation of a Markov Process

A 1D binary string has the following dynamics $$1100 \to 1010,\quad 1101\to 1011$$ each with rate \$p<1\$. That is if we see \$110\$ in the string, then we change to \$101\$ with probability \$p\$....
Kartik Chhajed's user avatar
3 votes
0 answers
306 views

Animation of an incremental rotary encoder

While reworking my teaching materials for an exercise of an introductory course on mobile robotics, I recently created a animation/simulation of an incremental rotary encoder, e.g. often used for ...
AlexV's user avatar
  • 7,234
3 votes
0 answers
315 views

Designing a configurable Discrete Event Simulation class

A bit of context: I've had a fair share of programming in Java but want to refine my C++ skills with a college task. I've wanted to focus on C++11 and C++14, as they are recent but not latest, and C++...
Alxe's user avatar
  • 131
3 votes
0 answers
1k views

A Java library for simulating logic circuits

I have this Java library for building logic circuits and running binary data through them: AbstractCircuitComponent.java ...
coderodde's user avatar
  • 27k
2 votes
0 answers
60 views

How can I shorten the runtime of my simulation?

Before you read the code below, note the following explanation: I have three classes: Driver, Vehicle, and ...
grimrol123's user avatar
2 votes
0 answers
96 views

Excel VBA animation runs slowly after editing worksheet

My VBA macro displays an animation based on a row-by-row time step simulation in the worksheet. The user enters the desired inputs and the worksheet calculates the evolution of the simulation in a ...
Paul N's user avatar
  • 21
2 votes
0 answers
64 views

Work environment simulator

This code attempts to solve a suggested challenge by myself a while back on meta, transcribed here for simplicity. Allocate resources efficiently on a work environment The company Code42Review ...
Bruno Costa's user avatar
  • 5,566
2 votes
0 answers
1k views

Lotto simulator in Python

I wrote a rather inapt lotto simulator in Python, showing how long it would take to win the jackpot. I ran a similar application implemented in C and it is so much faster. I know you can't compare the ...
royskatt's user avatar
  • 203
2 votes
0 answers
608 views

Routing simulation (Distance vector)

I am trying to write simulation for routing algorithm by distance vector. I will explain my class and how it works a bit, and then, introduce three main issues I encouter. Important to mention that ...
Unknown's user avatar
  • 63
2 votes
0 answers
4k views

Barrier Option Pricing using Python

This is my implementation of pricing an exotic option (in this case an up-and-in barrier option) using the Monte Carlo simulation in Python. I use NumPy where I can. Any ideas to optimize this code? <...
DudeWah's user avatar
  • 161
2 votes
0 answers
122 views

Sorting overlapping shells in dynamical simulation - for loops vs array methods

I didn't know whether it was best to start with the general task I'm trying to solve, or the meat of the programming problem. They're both below but the former is rather long and solving the latter ...
zephyr's user avatar
  • 143
2 votes
0 answers
86 views

Simulation of reflected particles

I made a particle simulation in vanilla JavaScript. It can currently handle around 10000 particles (staying 58-60 fps on my machine). For testing, controls are MB1, MB2, R, Z. How can I make this ...
user3050748's user avatar
2 votes
0 answers
446 views

Comparing three packet routing algorithms via simulation in Java

Inspired by my question Simulating a random packet routing algorithm and printing packet statistics in Java I decided to implement two more packet routing algorithms: one that computes all the ...
coderodde's user avatar
  • 27k
2 votes
0 answers
495 views

Physical simulation of diffusion-limited aggregates

The following code generates Diffusion Limited Aggregates on a two-dimensional square lattice. Some of the code has been omitted (e.g. support for differing lattice types and dimensions) for code-...
sjrowlinson's user avatar
2 votes
0 answers
615 views

PHP Lottery Simulator

I have a lottery simulator on my website that simulates you playing the lottery every week until your death and tells you how much you would have won or lost. It can take a custom number of balls and ...
Qiri's user avatar
  • 141
1 vote
0 answers
675 views

Solving the Knapsack Problem With a Genetic Algorithm Simulation in Python

I was watching Computerphile's video on using genetic algorithms to solve the Knapsack problem, and I decided to give it a whack. For anyone running the code, the ...
Jose Fernando Lopez Fernandez's user avatar
1 vote
0 answers
45 views

conditional simulation(path dependent simulation) in R

My codes are not good, I want to konw how to solve my problem efficicently and learn writing some elegant R codes.Thanks in advance! "r" is the starting value in ...
XUN ZHANG's user avatar
1 vote
0 answers
305 views

Blackjack simulator for Probability of a dealer bust for each starting card

I came up with this solution to another exercise out of John Zelle's Programming book. ...
Kevin's user avatar
  • 371
1 vote
0 answers
2k views

DP algorithm to find minimum average wait for customer-serving system

Below is the code to find the minimum average waiting time for customers at a store. I want improve the time complexity of the code. As an overview of the logic, I start from ...
Meena Chaudhary's user avatar
0 votes
0 answers
90 views

Simulation: Find a waiting queue order that minimizes the total waiting time - Java

Intro Suppose we are given a queue of waiting times \$\langle t_1, \ldots, t_n\rangle\$. The first "person" \$(t_1)\$ leaves the queue immediately. The persons \$(t_i), i > 1\$ all have ...
coderodde's user avatar
  • 27k
0 votes
0 answers
67 views

Bruteforce proof of an arithmetic expansion scheme expression in array lists (Java)

Given a list of, say, integers, one way to implement such a list is to rely on an array under the hood. When we are adding elements to the array list, we might need to make the internal array larger. ...
coderodde's user avatar
  • 27k