Simulating 100-Day Experiments with an Index Case

In summary, the individual is trying to simulate a 100-day period twice using a for loop statement. However, there is a problem with the code when the simulation is repeated as the index case needs to be reset to 1. The solution is to either add "index = 2" after the first loop or change the loop to "for index = 1:2".
  • #1
spoonyluv
9
0
Hello,

Here is my scenario: I am trying to run a code a 100 times, so I use a for loop statement i=1:100. The 1 to 100 stands for 1 to 100 days. Now I want to see how much randomness my results give and so I want to simulate this whole 100 days thing twice.

So I think my code would look something like this:

for m = 1:2
for i = 1:100

do something something

end
end

However here is the problem: within the code, do something something, i have this person that I have infected...I call him index case and initially assign him a value of 1 and within the period of 100 days I recover him and assign him a value of 2. so great. so the code works great from a period of 1-100. however when m=2 starts, I want the index case to go back to 1, and start the 100 day simulation again and I can't figure the best way to do that. The only thing I can think of is writing, towards the end, is when j > 100, index = 2, but I know that isn't right because Matlab will just ignore that part of the code since j never goes to greater than 100.

How do I get around this?

Thanks
 
Physics news on Phys.org
  • #2
Just put index = 2 after the first loop
Code:
index=1;
for m = 1:2
     for i = 1:100

     do something something

     end
     index=2;
end
 
  • #3
Or, instead of writing "for m=1:2", write "for index=1:2" and this should take care of everything
 

1. What is an index case in a simulation?

An index case in a simulation is the initial case or person that is used to start the experiment. This person is typically the first person to experience a certain event or disease, and their data is used as a starting point to simulate the outcomes of the experiment.

2. Why is it important to simulate 100-day experiments?

Simulating 100-day experiments allows scientists to study the long-term effects of a certain event or disease. It also allows for the observation of patterns and trends over time, providing a more comprehensive understanding of the experiment.

3. How do scientists determine the variables to use in these simulations?

Scientists determine the variables to use in these simulations by conducting thorough research and analysis of the experiment or disease. They may also consult with other experts in the field to ensure that all relevant variables are included in the simulation.

4. Can simulations accurately predict the outcomes of real-life experiments?

While simulations can provide valuable insights and predictions, they may not always accurately reflect real-life outcomes. This is because simulations are based on assumptions and models, which may not perfectly align with the complexities of real-life scenarios.

5. How can the results of these simulations be used in real-life applications?

The results of these simulations can be used in real-life applications by informing decision-making processes. For example, if a simulation predicts that a certain disease will have a significant impact on a population, this information can be used to inform preventive measures and resource allocation.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
560
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
29
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
Back
Top