Sign In | Subscribe

Enter your Sign on user name and password.

Forgot password?
  • Follow us on:
Start learning today, and be successful in your academic & professional career. Start Today!
Loading video...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of MATLAB
  • Discussion

  • Study Guides

  • Practice Questions

  • Download Lecture Slides

  • Table of Contents

  • Related Books

Lecture Comments (1)

0 answers

Post by Adegoke Adelabu on June 16, 2014

Hi: Please how can you simulate a satellite orbiting around the earth and showing its ground tracks in a resulting plot after the simulation is done?

Examples of Simulation

  • Simulation is an area of application where computers have come into their own. A simulation is a computer experimentwhich mirrors some aspect of the real world that appears to be based on random processes, or is too complicated to understand properly. (Whether events can be really random is actually a philosophical or theological question.) Some examples are: radioactive decay, rolling dice, bacteria division and traffic flow. The essence of a simulation program is that the programmer is unable to predict beforehand exactly what the outcome of the program will be, which is true to the event being simulated. For example, when you spin a coin, you do not know for sure what the result will be.

Examples of Simulation

Write a program to simulate the spinning coin problem, but in this exercise coin is not fair (i.e. the chance of having head is 60%). Do it for 100 times and display the ratio of number of heads over 100.
H = 0;
T = 0;
N = 100;
for i = 1:N
   r = rand;
    if r  <  0.6
         H = H + 1;
         T = T + 1;

disp('Head Percentage = ')
In a game of Bingo the numbers 1 to 99 are drawn at random from a bag.  Write a script to simulate the draw of the numbers (each number can be drawn only once), printing them ten to a line.
bingo = 1 : 99;
for i = 1 : 99
temp = bingo(i);
swop = floor(rand * 99 + 1);
bingo(i) = bingo(swop);
bingo(swop) = temp;
for i = 1 : 10 : 81
disp(bingo(i : i + 9))
disp(bingo(91 : 99))
Two players, A and B, play a game called Eights. They take it in turns to choose a number 1, 2 or 3, which may not be the same as the last number chosen (so if A starts with 2, B may only choose 1 or 3 at the next move). A starts, and may choose any of the three numbers for the first move. After each move, the number chosen is added to a common running total. If the total reaches 8 exactly, the player whose turn it was wins the game. If a player causes the total to go over 8, the other player wins. For example, suppose A starts with 1 (total 1), B chooses 2 (total 3), A chooses 1 (total 4) and B chooses 2 (total 6). A would like to play 2 now, to win, but he cant because B cunningly played it on the last move, so A chooses 1 (total 7). This is even smarter, because B is forced to play 2 or 3, making the total go over 8 and thereby losing. Write a script to simulate each players chances of winning, if they always play at random.
counter = 0;
for i = 1:1000

   ChofA = floor(rand*3+1);
   ChofB = floor(rand*3+1);

   while ChofB == ChofA
        ChofB = floor(rand*3+1);

   total = 0;
   if (ChofB hicksim = ChofA) (total  < = 8)
        total = ChofA + ChofB + total;
        temp = floor(rand*3+1);
        while (temp == ChofA)|(temp == ChofB)
             temp = floor(rand*3+1);
       ChofA = temp;
       total = total + ChofA;
   ChofB = floor(rand*3+1);
   ChofA = floor(rand*3+1);
   while ChofA == ChofB
        ChofA = floor(rand*3+1);
   total = total + ChofB;
   if total == 8
        disp('B wins');
        counter = counter +1;
   elseif total  >  8
        disp('A wins');
   elseif total  <  8
        disp('B wins');
        counter = counter +1;

disp('chance of B winning: ') disp(100*counter/1000)

*These practice questions are only helpful when you work on them offline on a piece of paper and then use the solution steps function to check your answer.


Examples of Simulation

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Example: Flipping Coins 0:34
    • MATLAB Equation
  • Changing Value of N 3:14
  • Example: Roll of Dice 3:49
  • Example: Random Walk 4:44
    • Illustration
    • MATLAB Equation
    • Probability