simulation

Is a functional language a good choice for a Flight Simulator? How about Lisp?

允我心安 提交于 2019-12-06 19:43:34
问题 I have been doing object-oriented programming for a few years now, and I have not done much functional programming. I have an interest in flight simulators, and am curious about the functional programming aspect of Lisp. Flight simulators or any other real world simulator makes sense to me in an object-oriented paradigm. Here are my questions: Is object oriented the best way to represent a real world simulation domain? I know that Common Lisp has CLOS (OO for lisp), but my question is really

Simulate data from lognormal in R

霸气de小男生 提交于 2019-12-06 15:54:17
问题 Suppose I want to simulate 10 observations from lognormal distribution and repeat this 100 times. I wrote some R code, but for some reason it's not working. Here is the code: for(i in 1:100) { x = rlnorm(10, meanlog = 0, sdlog = 1) } Any thoughts? 回答1: This could work: lapply(1:100, function(i) rlnorm(10, meanlog = 0, sdlog = 1)) EDIT To calculate the mean and sd use: lapply(1:100, function(i) { x <- rlnorm(10, meanlog = 0, sdlog = 1) c(mean=mean(x), sd=sd(x)) }) Or to return it in a matrix

Python 3.1- Grid Simulation Conceptual issue

老子叫甜甜 提交于 2019-12-06 14:37:45
The goal is to treat a 1D array as a 2D grid. A second 1D array gives a list of values that need to be changed in the grid, and a third array indicates by how much. The catch is that the values surrounding a modified value is changed also. The example below stays as a 1D array, but makes calculations on it as if it was a 2D grid. It works; but currently it changes all values in the grid that match to a value in the 1D list (sample). I wan't to only convert 1 value and its surroundings, for 1 value in the list. i.e. If the list is [2,3]; I only want to change the first 2 and 3 value that comes

Creating every possible team combination — combinatorial optimization

时光总嘲笑我的痴心妄想 提交于 2019-12-06 09:46:38
问题 Apologies if the title is not an accurate description of what I'm doing. I am trying to construct every possible hypothetical team for a fantasy sports competition. This means combining all available players, each of whom has characteristics like the team they are on, their position, and their salary, which limits how many can be on a single team. The trouble I am having is finding a memory efficient way to combine them all. I made an example dataset: player_pool <- data.frame(id = seq(1,30),

Why is my astronomy simulation inaccurate?

余生颓废 提交于 2019-12-06 07:45:36
I've made a program that simulates movement of bodies in the solar system, however, I'm getting various inaccuracies in my results. I believe that it probably has something to do with my integration method. tl;dr there's a slight difference between the position and velocity of Earth between my simulation and NASA's data, if you could please look at my code below and tell me whether my math is wrong. The test I've ran is a 10 day long (864000 seconds) simulation, that starts at Thu Mar 13 18:30:59 2006 and ends at Thu Mar 23 18:30:59 2006 . After the simulation the program reported the

Howto design a clock driven multi-agent simulation

旧时模样 提交于 2019-12-06 06:45:27
问题 I want to create a multi-agent simulation model for a real word manufacturing process to evaluate some dispatching rules. The simulation needs to produce event logs to evaluate time effect of the dispatching rules compared to the real manufacturing event logs. How can I incorporate the 'current simulation time' into this kind of multi-agent, message passing intensive simulation? Background: The classical discrete event simulation (which handles the time-advancement nicely) cannot be applied

Is there anything wrong with this shuffling algorithm?

ぐ巨炮叔叔 提交于 2019-12-06 06:11:41
问题 I have been doing a little recreational holiday computing. My mini-project was a simulation of the Italian game of "tomboli". A key building block was a simulation of the following process; The game is controlled by a man with a bag of 90 marbles, numbered 1 to 90. He draws marbles one by one randomly from the bag, each time calling out the marble number to the players. After a little thought I wrote the following code for this building block; // NBR marbles, numbered 1...NBR are in a bag.

Python using Kalman Filter to improve simulation but getting worse results

谁都会走 提交于 2019-12-06 05:55:17
I have questions on the behavior I am seeing with applying Kalman Filter (KF) to the following forecast problem. I have included a simple code sample. Goal: I would like to know if KF is suitable for improving forecast/simulation result for a day ahead (at t+24 hours), using the measurement result obtained now (at t). The goal is to get the forecast as close to measurement as possible Assumption: We assume the measurement is perfect (ie. if we can get the forecast matches the measurement perfectly, we are happy). We have a single measurement variable (z, real wind speed), and a single

Controlling memory allocation/GC in a simulation?

我与影子孤独终老i 提交于 2019-12-06 02:47:54
问题 I'm having a bit of trouble figuring out how to reduce memory usage and GC time in a simulation running in the State monad. Presently I have to run the compiled code with +RTS -K100M to avoid stack space overflow, and the GC stats are pretty hideous (see below). Here are relevant snippets of the code. Complete, working (GHC 7.4.1) code can be found at http://hpaste.org/68527. -- Lone algebraic data type holding the simulation configuration. data SimConfig = SimConfig { numDimensions :: !Int -

Flocking boids behaviour problem

岁酱吖の 提交于 2019-12-05 20:40:48
问题 Yesterday I came across Craig Reynolds' Boids, and subsequently figured that I'd give implementing a simple 2D version in Java a go. I've put together a fairly basic setup based closely on Conrad Parker's notes. However, I'm getting some rather bizarre (in my opinion) behaviour. Currently, my boids move reasonably quickly into a rough grid or lattice, and proceed to twitch on the spot. By that I mean they move around a little and rotate very frequently. Currently, I have implemented: