Create a set of functions that you can test

Assignment Help Simulation in MATLAB
Reference no: EM131036638

Lab 11a: Alien Invasion

Objectives

• Practice with MATLAB functions
• Learn about simulations and modeling
• Do analysis like a real engineer!

About

If you're a scientist or engineer of any sort and you have some sort of new product (bridge, electronic circuit, computer software, idea for scientific apparatus), the traditional way to test out your design has always been to build it and try it out. Perhaps one might start with building a smaller scale version for testing...but it was nonetheless based on building the artifact.

As it turns out, this is not only very expensive, but could actually be impossible in many cases. For instance, you develop a spiffy system to identify, target, and shoot down terrorist missiles; or maybe you're designing a strategy for containing the outbreak of some virulent disease; or maybe you're a doctor working on a new way to treat radiation poisoning. In all of these cases --- and many others where it's just too expensive or difficult to build the real thing --- science and engineering have come to rely heavily on computer simulation as a way to explore the behavior of a design. Although simulations can be incredibly complex, the basic idea is really simple:

1. You carefully build some sort of a model of your system.... either a small-scale prototype, or a numerical model of all the complete system. In the case of computer software, this might be the actual code for the system.

2. You then create a fake environment (sometimes called a test harness) for your system to function in. This environment essentially sends your system simulated input data to its inputs, allowing you to observe how your system responds/functions in light of those inputs.

More generally, the point of this assignment is to exercise your skills in a realistic scenario, and begin to pull together what we've learned this semester into actual viable knowledge you can use as an engineer.

Assignment

Your assignment is based on the following scenario: suppose you're working for ACME Space Defense, and the central project that the company is working on is a ray-gun defense system to shoot down incoming alien invaders. A prototype has been created, but desperately needs to be tested in simulation to avoid a complete disaster when it is actually built and tested in real life

As you may have inferred from the title, this assignment is the first of a two-week series. The objective in this first part, is to create a set of functions that you can test, and then later integrate into a simulator program. Breaking a program down into smaller, simpler parts is a common practice, known as functional decomposition. The biggest benefit of functional decomposition is that it isolates code by functionality, making the code much more testable, as you will see when you test this code for next week's pre-lab.

Implementation

Download the Lab11a folder from Bblearn. Move it to your cs122 directory, cd to the cs122 directory and add the Lab11a folder to the path.

Part 1 - randomFloatValue.m

This function accepts two numbers, lower and upper, and returns a random number between lower and upper, inclusive of lower and upper. The rand() function will be useful here.

Part 2 - getUserValue.m

getUserValue has three parameters:

- prompt: A string that is displayed to the user. This should be passed to your input function.
- lower: The lowest number that the user is allowed to input
- upper: The highest number that the user is allowed to input

This function should pass the prompt (which is a string such as ‘enter a number between 1 and 10') to the input function. Then determine whether the number that the user entered is between lower and upper, inclusive of lower and upper. If it is not, then ask the user again until a valid number is entered.

Part 3 - getFileName.m

This function should ask the user to enter a file name (remember the ‘s' flag with your input function). It should then check to make sure that the file ends in .txt. You will need to use the strcmp function to determine this. Then, if the file name does not end in .txt, the user should be asked until they enter a valid file name.

Part 4 - calculateBounds.m

calculateBounds has two parameters:

- a_rate: Rate to be used in the simulation.
- var: The percentage that a_rate may vary.

This function should calculate two things:

- lower_bound: a_rate - variation_amount
- upper_bound: a_rate + variation_amount

Keep in mind that variation_amount is not the same as var. var is the percentage variation from a_rate for lower_bound and upper_bound. variation_amount is the actual amount that lower_bound and upper_bound differ from a_rate.

To find variation_amount, we can multiply a_rate by var/100. We need to divide var by 100 because we need the fraction as a decimal number instead of a percentage.

Apply this to your calculations for the upper and lower bounds.

Part 5 - writeToFile.m

writeToFile.m has 4 parameters:

- filename: the name of the file that we will be writing to
- num_sim: the number of simulations that we want to write to the file
- lower: the lowest number of attackers possible
- upper: the highest number of attackers possible

The algorithm for this function goes as follows:

1. Open the file using filename, with write access.
2. Loop num_sim amount of times
3. Inside each loop iteration, generate a random number using your randomFloatValue function. The bounds for randomFloatValue are lower and upper.
4. Inside each loop iteration, use fprintf to write the generated random number to the file
5. Close the file.

Attachment:- lab_11a.zip

Reference no: EM131036638

Questions Cloud

Mathematical derivations of the equations : The article attached provides mathematical formulations that ought to be obtained analytically as mathematical derivations of the equations provided (section 2.2 unsteady state only) equations 5a - 5l
What are the most likely rain laden cloud types : Estimate surface runoff flood hydrograph if a 3-hr-storm excess rainfall temporal pattern is assumed as (2+R/10), (6+R/10) and (4+R/10) cm during each hour time step respectively.
Write a program that mimics a calculator : (For division, if the denominator is zero, output an appropriate message.) Some sample outputs follow:3 + 4 = 7 13 * 5 = 65
The left panel shows temperature versus depth : The graph on page 2 comes from a field program in the Eastern Pacific. Ocean probes descended into the ocean measuring both temperature and salinity.
Create a set of functions that you can test : As you may have inferred from the title, this assignment is the first of a two-week series. The objective in this first part, is to create a set of functions that you can test, and then later integrate into a simulator program.
Management of information systems : Explain the impact of databases on businesses. What industry has databases made possible? Give examples of database supported business applications or technology. Please state your response in 2-3 page paper in APA format. Include citations an..
What are your reflections on his spiritual journey overall : What is Nirvana? How would you define it? What is the middle path (or moderation) in Buddhism and how does Siddhartha discover this? What are your reflections on his spiritual journey overall?
What is the wavelength of the light being used : In a Young's double-slit experiment, the seventh dark fringe is located 0.027 m to the side of the central fringe on a flat screen, which 1.1 m away from the sites. The separation between the slits is 1.30 x 10-4 m. What is the wavelength of the li..
Determine the upward reaction at each support : State the position and magnitude of the maximum bending moment on the beam.

Reviews

Write a Review

Simulation in MATLAB Questions & Answers

  Determine the friction factor of the system

Determine the friction factor f of the system using the Secant method. Start with initial guesses f = 0.01 and 0.02, and perform two iterations

  Solve the linear system

Compute the rank of S manually and use the MATLAB function to verify the result - Solve the linear system of equations Ax = b using MATLAB.

  Negative feedback system with time delay

What T is required? Use Matlab to make a Bode plot for this value of T and draw the signal flow graph to represent the equations of the circuit. Use Mason's Rule to find the transfer function H(s).

  Build a simulation using newtons laws of motion

Build a new and different simulation of your own using Newtons laws of motion and Show the code and describe how it works

  Simulate using beam propagation method

Simulate using BPM (Beam propagation method) the following wave guid?

  Provide regression equation for intel stock excess returns

Provide the regression equation for the Intel stock excess returns when using S&P 500 excess returns and inflation as explanatory variables - What can you say about the significance of the regression coefficients?

  Discuss the direction of the phase plot

In a separate cell (called Summary Cell) - Discuss the direction of the phase plot with respect to its starting point, where the pulse turns off and at its final value

  Employ the use of word comparison instructions to control

Utilizing a single timer. employ the use of Word Comparison instructions to control our simulated traffic light. The sequence of operation and timing durations are set out in following timing diagram.

  How dc motors are physically constructed

How DC motors are physically constructed. How to test DC motors to assess performance. How to use Excel and MATLAB.

  Construct simulation to portray macrophage chasing bacteria

Construct simulation in MATLAB to portray a macrophage chasing a bacteria as it diffuses away and ultimately catching it if:

  Compute and plot the response of given system

Compute and plot the response of the following system using integration: 10x(t) + 20x(t) + 1500x(t) = 20 sin25t + 10 sin 15t + 20 sin2t

  What is the total variability in the dataset

This problem is aimed at helping you understand the PGA method using an idealized dataset Since you know the data you are generating. it should help you understand the capability of the method. Perform a principal component analysis on the dataset ..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd