Vous êtes sur la page 1sur 4

Lab: Plotting and Graphing Fireworks

Part A: Introduction
Fireworks have been around for hundreds of years. It all started when Li Tian, a Chinese monk,
stuffed a section of bamboo with gunpowder and lit it on fire. The loud bang was intended to
scare ghosts away.

While modern day fireworks have changed greatly, they are still composed of the basic elements:
a shell, an explosive, and a fuse. Scientists rely on a series of two reactions in order to get a
firework into the sky and exploded. It includes a fast-fuse and a slow-fuse traveling inside of a
long paper cylinder. At the bottom of the cylinder, the firework (an aerial shell) is placed on a
bed of gunpowder. The fast-fuse runs from the outside of the cylinder into the gunpowder. The
fast-fuse and short-fuse are lit at the same time; however, the first fuse works quicker to light this
gunpowder. Once the gunpowder is ignited, the unexploded firework shoots into the sky.
The inside of that firework is what will create the beautiful displays of color. An outer shell of
plastic or paper surrounds more gunpowder with explosive spheres (called stars) mixed
throughout it. The stars become the point of the firework we actually see. They are coated in a
variety of chemicals in order to create different colors.
Now that the firework is in the sky, it needs to explode. The second reaction involves the shortfuse running through the firework. The length is calculated in order to ensure the firework will
go off in the correct location in the sky. This fuse will set off gunpowder and stars located within
the actual firework, and the firework will explode.
Scientists can change the amount of gunpowder and type of fuse in order to include more noise
or create distinguishable shapes.
Source: http://www.theverge.com/2013/7/4/4489980/how-do-fireworks-work

Part B: Predicting the Stars Path


Stars shoot out in all directions once a firework is lit. With this lab, we will have more control
and will only work in a two-dimensional setting.
Once it is shot into the sky, the shell can explode in a variety of places. For example, the diagram
below represents the sky. A 0 shows where no part of the firework has reached. A * shows
where the firework have exploded over time. Assume that these fireworks expand only
diagonally. After each iteration, the firework will expand once in the four directions as
demonstrated from Table 1 to Table 2.
FILL IN TABLES 3 AND 4.
0

0 0

0 0

0 0

0 0

0 0

0 0

0 0

0 0

Table 1: At time of explosion

Table 2: After one iteration

Table 3: After two iterations

Table 4: After three iterations

Part C: Plotting One Firework


Using what you learned from Part B, we will now plot one firework using MATLAB.
1. Ask the user to input variables X and Y to show the X and Y position of the firework
explosion.

2. Check to see if the user entered an incorrect value (i.e. X is a negative number). Use a
different while loop to check each variable.
3. Now plot the original starting location using asterisks (*). Add a title.
4. You will want your firework to all plot on the same graph. Therefore, add a hold on
command.
5. Add the following code in order to keep the plot the same dimension:
xlim([X-20 X+20]); ylim([Y-20 Y+20]);

6. Using a for loop for three iterations, plot the firework over time. After each iteration, the
stars should expand one more space. You should be able to see the stars path; therefore, add
the hold on command after each plot. In Part B, you only plotted diagonally. Here, you will
plot in eight directions: the four diagonal directions and up, down, left, and right.
HINT: Think of the relationship between the original plot point and the new plot point in
order to graph each star.
7. Add a count. You can use this variable to plot each point if you would like.
8. Within your for loop, you should also include the pause command. It will help you see the
firework explode and animate your plot. For example, pause(0.5) would pause the code for
0.5 seconds.
9. Plot your results for the final graphs below.
PLOT FOR X=25 AND Y=25:
PLOT FOR A POINT OF YOUR CHOOSING X=___ AND Y=____:

PASTE SCRIPT FOR PART C BELOW:

Part D: Simulating Multiple Fireworks


1. You will edit your code from Part C in order to include multiple fireworks. Add an input
statement to ask the user how many fireworks they would like to set off at once.
2. Add an input statement to ask the user how many iterations they would like the fireworks to
go off for.
3. In Part C, you had the user input X and Y values. In actuality, the location of explosion will
vary based on a variety of factors like wind and drag force. For Part D, create random X and
Y location values for the total number of fireworks the user wants to see. The command

randi(250, 1, Number of Total Fireworks) will create a list of random numbers between 1
and 250. The list will be the same length as the number of total fireworks requested as long
as you use the same variable as your input statement.
4. Edit your xlim and ylim commands to take into account the new limits.
5. Create a new color each time you run your code. You can do this by adding C=rand(1,3)
before the for loop and initial plot. Within each plot command, you will also add the color
command and C as shown for the initial plot below:
plot(X,Y,'*','color',C);

6. Plot the graphs below.


PLOT FOR 15 FIREWORKS AND 15 ITERATIONS:
PLOT FOR 5 FIREWORKS AND 40 ITERATIONS:
PLOT (OF YOUR CHOOSING) FOR _____ FIREWORKS AND _____ ITERATIONS:

PASTE SCRIPT FOR PART D BELOW:

TO BE TURNED IN: LAB WORD DOCUMENT WITH TABLES FILLED OUT AND
MATLAB CODE PASTED WHERE INDICATED.

Vous aimerez peut-être aussi