r,simulation,vectorization,lapply

It's true that a <- t1() works but it's not true that a <- t1(2) would have "worked". You are trying to pass arguments to parameters that are not there. Put a dummy parameter in the argument list and all will be fine. You might also look at the replicate...

Why Zero delay loop happened? Due to race condition or ambiguous coding style zero delay loop may get generated which results in simulation hung or infinite simulation time What are the causes of Zero delay loop? One example of a common loop behaviour as follows: always @ (x) begin...

matlab,cuda,simulation,simulator,simulate

Well that was definitely a funny exercise. This is a completely rewritten answer since you found the issues you were asking about by yourself. Instead of deleting my answer, there is still merit in posting to help you vectorize and/or explain a few bits of code. I completely rewrote the...

It happens because your initial conditions give the system a non-zero net momentum. You can fix that by calculating the initial mean velocity of the system and subtracting it from all the object velocities: double vxavg = (vxsun*ms + vxearth*ma) / (ms + ma); double vyavg = (vysun*ms + vyearth*ma)...

Yes, I believe what your asking is possible. I personally use a VB script running on a PC to write to registers in a PLC... so that's one way to do it.

Background on time Semantically I would recommend using time over integer, behind the scenes they are the same thing. But as it is only an integer it is limited to the accuracy of the timescale time_unit*. Therefore I would suggest you actually use realtime which is a real behind the...

python,vector,simulation,trigonometry

Try fixing the boundary condition where alpha+beta and beta-alpha lies on either side of the positive x-axis. Assuming all your angles, beta and theta lie in the range (0, 2*Pi), this might work : def checkMargingForTheta(alpha, beta, theta): low = beta - alpha high = beta + alpha if(high >...

You have to create a new list of Get events in each iteration. If your re-use the old list, it will still contain the triggered event from the first iteration. This should work: inchannel = [simpy.Store(env) for i in range(3)] while True: # Make a new list of Get events...

javascript,math,vector,simulation,physics

Center-center distance in the touch moment is R12 = R1 + R2 So using cosine theorem: R122 = v'2 + d2 - 2*d*v'*Cos(dv) Solve this quadratic equation against v' and get smaller positive solution value (if 2 cases exist). You can find Cos(dv) through scalar product of vectors d and...

simulation,distribution,exponential

What you're doing is called a time-step simulation, and can be terribly inefficient. Each tick in your master clock for loop represents a delta-t increment in time, and in each tick you have a laundry list of "did this happen?" possible updates. The larger the time ticks are, the lower...

python,simulation,try-except,simpy

I made some progress and came up with a solution. Multiple interrupts do not require nested try except statements. Separate statements also seem to work. After some trail and error I found out that it is also possible to use separate try except statement. The first interrupt starts a counter....

python,scripting,simulation,maya

In this case I think it's actually the flags on bakeResults. I was able to get this to work in a maya standalone: import maya.mel import maya.cmds as cmds cmds.file(new=True, f=True) cmds.polyCube() cmds.polyPlane(sx = 21, sy = 22) cmds.xform(t= (.0005, .015, .0005)) # note units - my maya is working...

routing,simulation,ibm-connections,city,traffic-simulation

Check out http://sumo-sim.org. It is a fully featured open source traffic simulation. You can either get a static trace of vehicle positions or you can access these values via an API and trigger re-routing in a running simulation. The documentation is at http://sumo-sim.org/wiki and you can get help at [email protected]

java,android,swing,simulation,ui-virtualization

You just can't. Android applications requires a lot of dependencies that are not available in the classic Java environment. However, you can run Android applications on your desktop through some emulators such as Andy or BlueStacks....

c,multithreading,linked-list,pthreads,simulation

This code right here looks wrong: curr = head -> next; head = curr -> next; Consider the case where your list looks like: head -> node -> dummy. After running the above code, head will be pointing at dummy, which you surely do not want. Try changing the code...

I have run simulations much longer than this in ISIM, so this points at your code, I think. Two ways forward: Try another simulator, perhaps ghdl (free) and see if it reports a problem that ISIM doesn't. It is usually stricter (more standard compliant) than ISIM and can sometimes diagnose...

c#,winforms,simulation,simulator

Each button at any specific time shall execute some specific action depending on the state of the system. Obviously, if you try to decide the specific action depending on the multitude of different variables, you will create a lot of branching code. Such code is very difficult to write correctly...

verilog,simulation,hdl,modelsim

As parameters are compile-time (technically elaboration-time) constants, you cannot have them change during the course of execution. Thus, the first error in which sob.w was set to n is not valid as n cannot be determined to be a fixed value during the elaboration phase (part of compiling the entire...

linux,unix,real-time,simulation

This is an old question, but may as well answer it. Short answer is no. FSUIPC and the P3d API both run on Windows and are the only solutions I know of to communicate with the sim. You could, however, write a wrapper for the API that receives UDP packets...

I'd like to randomly generate 32 lines of hex strings Random rnd = new Random(); int bits = 12; // bits in "byte" int length = 10; // number of "bytes" in string int n = 32; // number of strings for (int i = 0; i < n;...

r,loops,simulation,montecarlo,expensive-resources

A few ideas: R is really not good at this kind of iterative process. A compiled language will perform much better. I'll assume here that you want to stick with basic R. Learn to use the profiler to see where your implementation is wasting time. See the example at the...

As @BondedDust said, t is a flag that indicates whether the while loop should continue or end. As an example to see how it works you can change your sample to n=3. n=3 #sample size lambda=8 #parameter u=runif(n) x=0 for(i in 1:n){ cat ("i=" , i, '\n') t=-1 g=exp(-lambda) #...

There was an error in the original solution. The new solution i've posted rectifies the error.

to my knowledge there is no method like: .moveforward() you could use your current position: .getXYZ() and direction: getRotation() to calculate a point some distance: r, in front of your agent and then use the .moveToStraight(x,y) x = r * cos(direction) + x_0 y = r * sin(direction) + y_0...

One way is to assign a cumulative sum column to mtcars so you're not having to recalculate that all the time. mtcars$cumsum <- cumsum(mtcars$count) Car.ID <- function(x) { if (x < mtcars$cumsum[1]) { return(paste(rownames(mtcars)[1], x, sep = ":")) } else { row <- tail(which(mtcars$cumsum < x), n = 1) return(paste(rownames(mtcars)[row...

c#,algorithm,simulation,physics,numerical-methods

Your model calculates the gravity force between two particles twice: for the first particle the force is based on their original coordinates, and for the second particle it is based on an updated position of the first one. This is a clear violation of the Newton's 3rd law. You must...

Are you telling Modelsim to search the libraries for you modules during elaboration? For example you should pass the following arguments to vsim: vsim -L lpm_ver ... Often pre-compiled Verilog libraries are suffixed "_ver" so make sure you are referencing the correct library....

You could add at the end of the loop: x = [1 2 3 4 5; 4 5 6 8 9; 8 7 6 3 1; 5 6 7 9 1; 6 4 2 9 6]; y = [10 30 24 35 40]'; one=[]; for ii=1:5 one = x(:,ii); [b_LS,...

I deleted and re-added design & simulation sources, which still left the black-box. I opened a new project and added the sources before the project was created and the simulation ran without a problem.

I hate to be that guy who answers their own post but I just found the same example used on page 15 here in the "rpart" documentation. I'll continue writing up the answer but I'll delete the question at the end of the day unless I hear differently from the...

java,oop,object,simulation,traffic-simulation

You should have a Look at the SourceCode of LinkedList and maybe adapt this principle. A road has 2 connection points, while a intersection maybe 2 to 4? Abstract class RoadElement{ //abstract for simulation purpose, maybe randomized //calculation of next direction, etc. } class Road extends RoadElement{ private RoadElement previous...

c++,assembly,x86,simulation,bitstuffing

To stuff the new bit you multiply by 2 which is just a convoluted way to do a shift left. This will discard the most significant bit, so you are not discarding from the least significant position of the original value, rather, you are basically overwriting the following bit with...

design,file-io,verilog,simulation

File input output operation can be done without initial blocks based on some condition, I have shown one example were file write happens based on high and low conditions of reset. module tb(); reg out,temp; reg clk,reset; integer f,f1,i; always #5 clk=~clk; initial begin clk=0; reset=0; #50; reset=1; #50; reset=0;...

Assuming you really need to sample from a normal distribution, you can probably DIY http://en.m.wikipedia.org/wiki/Marsaglia_polar_method or http://en.m.wikipedia.org/wiki/Box–Muller_transform There is an open issue for truncnorm as currently implemented in scipy https://github.com/scipy/scipy/issues/2477. The original ticket gives links to several alternative implementations....

c#,.net,network-programming,simulation,network-protocols

Assuming you want to create a single threaded simulation, you have two choices - a time driven simulation, or an event driven one. The difference between the two being the way in which the simulation time (or simulation clock) advances. The way in which time advances determines the way in...

You can improve the speed of your function by using data.table. However, you would still have to use for loops (which is not a bad thing). library(data.table) simdiffuse <- function(a, b, c, d) { endo <- 1/a # innovation endogenous effect endomacro <- 1/b # category endogenous effect appeal <-...

python,shell,simulation,argparse

A dict is what argparse ultimately uses to host its Namespace, so, no problem using one directly. Module ConfigParser, https://docs.python.org/2/library/configparser.html , will parse a rather normal config file and store the settings in it for you. It is, however, arranged by sections. To extract a single section 'foo', given a...

r,performance,for-loop,simulation

Apologies for the long-winded answer, but there's a lot going on here. First, some housekeeping. At each iteration of the outer loop, you seem to want to calculate the mean of all the pairwise distances across two random samples of size 4000 and 5000 (so, the mean of 20 million...

c++,opengl,visualization,simulation,heatmap

It is definitely feasible, probably even if the calculation are done by the CPU. Ideally you should be using the GPU. The APIs needed are either OpenCL or since you are rendering the results you might want to make use of Compute Shaders. Both techniques allow you to write a...

What you built is a sequential logic, meaning that the outputs depend on the previous hystory of the inputs/outputs. In your case we have Qa, and Qb which is the last value of Qa. Keeping this in mind, the approach you have used in the testbench is not optimal, because...

Create a global int variable such as sentPackets in the node class which will keep track of the packets that are sent. And in order to inspect it later on, use the WATCH() macro. More info: http://www.omnetpp.org/doc/omnetpp/manual/usman.html#sec295...

The X is from having multiple conflicting drivers on bb_sample and ddc_out_enable. The wire type merges the drivers, conflicting bit values of the same strength resolve as X. UUT_rx_dsp0 is the intended diver. However you added and additional drivers from the way you declared your wires. ... wire [31:0] bb_sample...

simulation,high-level-architecture

So eventually I found that Portico was creating a log file located in my VBS directory\logs. From there I was able to see that Portico at least was not able to find my .fed file I had the path messed up.

python,simulation,precedence,simpy

I should do this as a comment, but I don't have the reputation to do so. Nevertheless, I think it might help with your problem. I am not familiar with simpy but you might be confusing triggered and processed which is not allowing task B to execute; check this link:...

concurrency,verilog,simulation,blocking,assign

Without diving too deep into the simulation cycles used by Verilog Simulators, you can think of non-blocking vs blocking assignment simply as this: Blocking assignment happens inline at the time the given assignment is executed, so that means if I have a line like A = A + 1, that...

r,function,arguments,simulation,quantile

An illustration of my comment above: etacor1 <- function(rho = 0, nsim = 1e4, fx = qnorm, fy = qnorm, fx.args = formals(fx), fy.args = formals(fy)){ #generate a bivariate correlated normal sample x1 <- rnorm(nsim) x2 <- rnorm(nsim) fx.arg1 <- names(formals(fx))[1] fy.arg1 <- names(formals(fy))[1] if (length(rho) == 1){ y <-...

If you need to generate a new person entity every 2-6 seconds, why not generate a random number between 2 and 6, and set the timer to wait that amount of time. When the timer expires, generate the new customer. However, if you really want the equivalent probability, you can...

Your processes request a resource and never release it. That’s why the second trains waits forever for its request to succeed. While it is waiting, the failure process seems to interrupt the process. That’s why you get an error. Please read the guide to resources to understand how SimPy’s resources...

java,swing,simulation,jtextarea

Steve's solution with changing the default caret works very well, but there is also another solution and that is to execute all the key presses in the main thread like this: java.awt.EventQueue.invokeLater(new Runnable() { public void run() { // dispatch the event now text.dispatchEvent(new KeyEvent(text, KeyEvent.KEY_TYPED, 0, 0, KeyEvent.VK_UNDEFINED, 'H'));...

I don't think there is exactly such tool, but there is a list of Ansys approved text editors and other helpful programs (digitizers, CAD converters e.t.c). I guess, if there will be any good framework, it must be listed there....

javascript,c#,web,simulation,imacros

If you want it for .net, then there is WatiN. Here is an example how to use it: public void SearchForWatiNOnGoogle() { using (var browser = new IE("http://www.google.com")) { browser.TextField(Find.ByName("q")).TypeText("WatiN"); browser.Button(Find.ByName("btnG")).Click(); bool contains = browser.ContainsText("WatiN"); } } p.s. You can also try Test Recorder for generating macros....

Within JavaFX framework, you can simply use PauseTransition to simulate periodic time elapsing. On end of every period update scene graph elements' states. If you are going to change some properties of some node and do various animations you may utilize other types of Transitions. For more fine grained control...

simulation,distribution,exponential-distribution

It's not an error to get zero. With exponential interarrival times and a rate of 3 per hour, the number of occurrences in an hour has a Poisson distribution with λ=3. The probability of getting n outcomes is e-λλn/n! which for n=0 is just under 0.05. In other words, you...

Here is a simple solution: sim.cor <- function(R, Marginal, n, K) { res <- numeric(length = K) for(i in 1:K) res[i] <- cor(ordsample(n, Marginal, R))[1,2] res } where n is the sample size and K is the number of times you want to repeat. So, in your example, you can...

windows,fork,posix,simulation,createprocess

In Windows, you simulate fork with CreateThread, unless it's followed by exec, in which case you ues CreateProcess. The fork system call creates a clone of your process. The exec system call loads a new program into your process, replacing the old program....

You could use Matlab's in-built function GPlot The second matrix you are referring is the 'Adjacency matrix', while the first matrix is the 'coordinates'. %// as your actual coordinates are in 2nd and 3rd column Coordinates = Location(:,[2 3]); gplot(Adjacencymatrix,Coordinates); ...

c++,function,graphics,return-value,simulation

Ok. I got it. After hours of investigation I realized that the problem it not related to atan2() function or some sign change of the angle when it comes to jump over 180° or 360°. Reading carefully the following code as as example #include <string> #include <ros/ros.h> #include <sensor_msgs/JointState.h> #include...

c++,multithreading,performance,simulation,landscape

1) The only other way of doing this well, which I can think of, would be with the Cartesian distance formula, but your way seems like it would have less CPU time (since the Cartesian way must calculate to every point on each point). 2) Or, if I understand your...

c,multithreading,simulation,cpu-usage

Your code is serial. You have eight available threads (4 cores * 2 threads per core = 8 total threads), and your current code uses one of them for 1 thread / 8 available = 12.5% of your CPU. If you have to write your own code (and not use...

The Verilog languages are quite low level so when designing hardware for FPGA or ASIC we have combinatorial logic and sequential logic. Assertions in any tools are really for verification, the concept is to high level to be able to get the hardware you want. SystemVerilog is not just for...

The answer is called "thinning," but requires you to know the global maximum arrival rate λmax. Generate arrivals at rate λmax, but for each generated arrival at time t, only execute the arrival event with probability λt/λmax. You can do this by generating a uniform(0,1) random number U for each...

The div function uses a loop where the exit condition never becomes true, whereby the div function will never return, thus the simulation time will never advance. One relevant part of the div code is in: elsif num2 > num1 then v_TEST_VARIABLE1 := to_integer(unsigned(num1)); v_TEST_VARIABLE2 := to_integer(unsigned(num2)); L2 : loop...

python,class,reference,simulation

from collections import namedtuple Connection=namedtuple("Connection",["source","strength"]) class Unit(object): # these first two methods just let me set up units and connections: def __init__(self,par=1, response=[0], connections=[]): self.par=par self.response=response self.connections=dict()#[] def receiveConnection(self,source,strength,label): # source is some other variable, strength is probably fixed but # i'd like it to be able to change, too...

verilog,simulation,hdl,modelsim

The are small example to show the issue: module tb; reg [2:0] month[3:0][3:0]; initial begin month[0][2] = 3'b011; month[0][3] = (month[0][2]+28)%7; month[0][4] = (month[0][3]+31)%7; $display("2: %b", month[0][2]); $display("3: %b", month[0][3]); $display("4: %b", month[0][4]); end endmodule The problem you have is month[0][4] when the definition is reg [2:0] month[3:0][3:0]; You can...

r,statistics,simulation,probability

If you inspect the body of the function ks.test you will see the following line somewhere in the body: if (length(unique(x)) < n) { warning("ties should not be present for the Kolmogorov-Smirnov test") TIES <- TRUE } This tells you that when the number of unique elements in x is...

java,design-patterns,data-structures,simulation

You can use a Map of type Enumeration -> Integer, where the integer indicates how many of each there are. The google guava "MultiSet" does this for you, and handles the edge cases of adding an enum to the set when there is not already an entry, and removing an...

r,list,function,data.frame,simulation

Perhaps something like this? n = 10000 mu = 0 sd = 1 n.sub = 100 iboot = 100 isim = 1000 sd <- c(1,10,100,1000) n.sub <- c(4,10,100,1000) iboot <- c(100,1000,10000) # hist.fn parameters: n,mu,sd,n.sub,iboot params <- expand.grid(n = n, mu = mu, sd = sd, n.sub = n.sub, iboot...

types,simulation,system-verilog,modelsim

You are not allowed to make procedural assignments to wires.. To make a connection, you need to use a continuous assignment as you did in the 1st module.. To do that, you need a generate-for loop.. Something like: for (genvar var_a=1; var_a<=0; var_a--) begin for (genvar var_b=1; var_b<=0; var_b--) begin...

c++,algorithm,math,statistics,simulation

I will change this comment into an answer since I have more: I like ELO ratings. Harkness wrote a book many years ago describing how the US Chess Federation implemented its rating with an extension of a basic ELO system. As an aside when a new player would be establish...

The quickest way I can think of is to take advantage of the vectorisation built-in to rnorm. Both the mean and sd arguments are vectorised, however you can only supply a single integer for the number of draws. If you supply a vector to the mean and sd arguments, R...

I assume you are talking about this model: This model already models your first request. The "magic" is done in the NeedAdditionalService element where 30% (the specified value is 0.3) of all customers that are done at the ATM are sent to the cashiers, because they need additional service. You...

c,multithreading,struct,pthreads,simulation

There's quite a few mistakes and typos you made. The first mistake is here: struct shiftInfo *Q = malloc(sizeof(struct shiftInfo) + (maxCust*sizeof(int))); struct shiftInfo info; info.simTime = atoi(argv[1]); info.arrivalRate = atof(argv[2]); info.tellers = atoi(argv[3]); info.serviceTime = atoi(argv[4]); info.sampleInterval = atoi(argv[5]); //Initiates Q to 0 for (int i = 0; i...

It helps if you separate the differential equations from the RK4 implementation. Then you can implement RK4 as in the documentation k1 = f1( y1, y2, x) l1 = f2( y1, y2, x) k2 = f1( y1 + 0.5*h*k1, y2 + 0.5*h*l1, x + 0.5*h) l2 = f2( y1 +...

The simplest answer would be that new QThread provides thread-local event loop, thus you can move your simulation into new QThread (see Per-thread event loop). However, without more details about your simulation I can only assume it will meet your needs.

So, you can use replicate instead of a for loop, wrap it in a function, and then you're done. time<-c(65,130,195,260) initial<-.5 # I assume a,b,c,j are constants a<-b<-c<-j<-1 # Use replicate instead of a four loop to generate your matrix directly: mat<-replicate(10,(initial*exp(-a*(time/260)) + b*(1-exp(-a*(time/260))) + c*(j/260))*rnorm(1)) # Get the means...

(double) rand() / (RAND_MAX + 1) is a dangerous expression. If, as it often happens, RAND_MAX is equal to INT_MAX then RAND_MAX + 1 is an overflow and undefined behaviour (it usually results in INT_MIN but this is not guaranteed by any specification). In Visual C++ RAND_MAX is 32767 and...

simulation,voip,ns-3,qos,wimax

From my short experience, Generally you need to use the flowMonitor helper class to get the statistics. Refer below. http://www.nsnam.org/doxygen/classns3_1_1_flow_monitor_helper.html If it is just the basic statistics like bytes received, sent etc, you have already functions in the packet class that can be used to get the values. Else you...

embedded,vhdl,simulation,synthesis

As you've probably realized by now, VHDL is not a programming language but a Hardware Description Language. It is very easy to get confused about the terminology cause HDL doesn't work like software. Simulation consists of using a simulator (surprise) such as ModelSim to interpret your VHDL code while stimulating...

MassData md = new MassData(); gives zero rotational inertia: md.I == 0 so the box doesn't rotate. If you do MassData md = body.getMassData(); you will have mass and rotational inertia according to your current density. The best way to change mass and get the correct rotational inertia - calculate...

module,simulation,verilog,processor

You are not telling Verilog that the instruction is a binary number, so it is interpreting it as decimal. You need this: instruction = 32'b00100000000010000000000000000001; #100 //add $8, $8, $8 instruction = 32'b00000001000010000100000000100000; Additionally, you should not be putting assign statements inside an always block. If you want these to...

python,random,simulation,normal-distribution

You can generate the random numbers using random.gauss. For example I'll create a list of 10 random numbers, with a mean of 10 and standard deviation of 1 >>> import random >>> nums = [random.gauss(10, 1) for _ in range(10)] >>> nums [11.959067391283675, 9.736968009359552, 9.034607376861388, 9.431664007796622, 11.522646114577977, 9.777134678502273, 10.954304068858296, 9.641278997034552,...