2

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

winny
  • 13,064
  • 6
  • 46
  • 63
Hari
  • 1,496
  • 11
  • 22

1 Answers1

3

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.

Rohat Kılıç
  • 26,954
  • 3
  • 25
  • 67
  • 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. – Hari Mar 14 '23 at 14:48
  • 1
    @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. – Rohat Kılıç Mar 14 '23 at 15:05
  • 1
    `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". – Kuba hasn't forgotten Monica Mar 14 '23 at 15:21
  • Tolerance value divided by the run time intervals, added and subtracted from the stated resistance value.Please correct me if I am wrong – Hari Mar 14 '23 at 15:41
  • 1
    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 – jDAQ Mar 14 '23 at 20:53
  • @jDAQ you are right. My mistake. `run`, unlike `time`, is not a global/special variable. The simulation requires a dummy iterator. Doesn't have to be `run`. I used it in my random generator in the past, probably that's why I confused. Thanks for pointing out. – Rohat Kılıç Mar 20 '23 at 08:27