Excel VBA Code

Job ID: 32827859

Budget: $10 – $30 USD

could develop the vba code for the following problem?

Excel VBA Coding



Code a function in VBA that emulates the pseudo-instantaneous diffusion of a particle from an initial position (xi, yi, zi) to a final position (xf,yf,zf), which can occur over a variable interval of time (Δt). We will use a general method known as Kinetic Monte Carlo (KMC), which implies that an element of randomness will be involved. Specifically, the change in position and time will be given by the following algorithm:
1. Choose a random number (RN) from 0 to 1.
2. Use the random number to select 1 out of 3 possible events, each with different
probabilities:
a. The particle has Δx (i.e. xf – xi) = 1; this occurs with probability 0.58.
b. The particle has Δx (i.e. xf – xi) = -1; this occurs with probability 0.23.
c. The particle has Δx (i.e. xf – xi) = 0; this occurs with probability 0.19.
Hint: the RND() function selects a number from 0 to 1 with uniform probability. You can use your current RN to select event (a) with the correct probability (in the limit of infinite samples) if you use the (RN <= 0.58) conditional. Can you setup additional conditions for events (b) and (c)?

3. Repeat steps 1 and 2for the y and z positions (new random number but same events and probabilities).
4. Choose a new random number (RN) from 0 to 1.
5. Compute Δ? =−ln(??)/0.8666
6. Return Δx, Δy, Δz,and Δt as an array
Use your code to predict a "trajectory" of the particle, which starts from x, y, z, and t = 0 (positions in meters and time in seconds). Make sure you extend the calculation so that the final t is at least 50 seconds. Compute your predicted radial diffusion rate (with units) using linear regression, i.e. what is a in the following expression:
? = ?? + ?
where r is the radial position, t is time, and (a,b) are constants. You can perform linear regression by fitting a trendline within a plot, using Data Analysis Regression, or using SOLVER.
Related categories: Excel VBA Excel Macros