3
\$\begingroup\$

I am learning about LTspice MC analysis from this site. I understood almost all the things except the below one.

"Then make another spice directive to execute a Monte Carlo run as below .step param run 1 100 1 The above syntax means that we are going to run the simulation for 100 times with starting point at 1 and the increment is 1. " My question here is,

What we are incrementing with a value of one. Here all the tolerances are fixed. (Please correct me if I am wrong).

Is this something like in the 1st iteration we take resistor value as R = R+Tolerance and in 2nd it is like R-Tolerance, something like that.

Are they running 100 permutation and combination like this:

enter image description here

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

What we are incrementing with a value of one.

You are incrementing the parameter run which is a public/global and special variable for LTspice's internal use.

Is this something like in the 1st iteration we take resistor value as R = R+Tolerance and in 2nd it is like R-Tolerance, something like that?

No. mc() function is something like a random generator between the given boundaries with a uniform distribution. In your circuit, at each iteration, each resistor will have a random value within the range set by their minimum possible and maximum possible values (i.e. in \$[R(1-tolb), R(1+tolb)]\$ range).

The simulation requires a dummy iterator, hence the parameter run driven by .step param function.

And this function takes the parameter run (as stated before, a special variable for LTspice, just like time) as input, so you need to manually increment it at reach iteration so that the random generator doesn't generate the same value. That is what .step param function does.

CORRECTION: run is not a global variable. In one of my earlier simulations in the past I used run as a parameter for my random generator. That's probably where my confusion comes from. Sorry for the wrong information.

\$\endgroup\$
6
  • \$\begingroup\$ A 100 ohms resistor with 10% tolerance may have values ranging from 90 ohms to 110 ohms. The mc function generate random values between 90 and 110 ohms. If number of iterations are more the number of random values also will be more. Please correct me if I am wrong. \$\endgroup\$
    – Confused
    Commented Mar 14, 2023 at 14:48
  • 1
    \$\begingroup\$ @Hari true. mc() function is useful when the number of iterations (basically, number of samples) are high (e.g. greater than or equal to 100). This means that having high number of iterations decreases the possibility of having the same value across the runs. You can write your own mc() function if you are not happy with embedded mc()'s outputs. \$\endgroup\$ Commented Mar 14, 2023 at 15:05
  • 1
    \$\begingroup\$ mc() is a uniform distribution generator producing floating point values. The probability of getting the same value twice from mc() would be zero if it was outputting real numbers. Even with finite precision floating point that probability is still very low. For float, even with narrow tolerances, it'd be lower than 1 in a million or so. For a couple thousand runs, the expectation is that mc() just doesn't produce the same number twice "ever". \$\endgroup\$ Commented Mar 14, 2023 at 15:21
  • \$\begingroup\$ Tolerance value divided by the run time intervals, added and subtracted from the stated resistance value.Please correct me if I am wrong \$\endgroup\$
    – Confused
    Commented Mar 14, 2023 at 15:41
  • 1
    \$\begingroup\$ Is run really a special variable? To me it seems that any iterator name would do the job, what matter is doing the .step for as many iterations as you would like \$\endgroup\$
    – jDAQ
    Commented Mar 14, 2023 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.