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

  Calculate the mid-point of the hermite curve

Calculate the mid-point of the Hermite curve that fits the points and the tangent vectors

  Model predictive control with shell standard control problem

Design Model Predictive Control on Shell Control Problem - strongly interactive and there are a great number of input as well as outputs. PID controller could do the good job for controlling the process but Model Predictive Controller could definit..

  Project is on load frequency control using fpid

Project is on load frequency control using FPID tuned using GA and PSO algorithm and the system is a two area system.

  Build a matlab based graphical user interface

Build a Matlab based graphical user interface (GUI) that operates in conjunction with a base Matlab/ Simulink simulation program. Any base simulation is considered acceptable.

  Generator and degradations - acquisition

Plot the autocorrelation function and show that other than peak there are only three values in the autocorrelation. What are the values of the autocorrelation function?

  Impact of zigbee on telecommunication systems

Topic is impact of zigbee on telecommunication systems. In this report you need to either do some measurement or do matlab code or simulation.

  Produce a simulation of the mechanism motion

Write a code to produce a simulation of the mechanism motion using the equation written in red in the file.

  Calculate the stress intensity factor

Use the three-parameter zone finite element method or the boundary collocation method to calculate the stress intensity factor K, at the crack tip for the plate

  Create a simulink model for the scara robot depicted

Create a Simulink Model for the SCARA robot depicted - The motor specification is appended to this brief - create a subsystem to model the motors taking into account that the inertia of Arms 1 and 2 combined is not a constant but depends upon the..

  Design a controller for a wind power induction generator

Design a controller for a wind power induction generator with battery connected and grid connected to "improve harmonics level". The controller can be reactive power control method.

  Calculate reading ease score and grade level for each book

Initialize 3 arrays with the data from the table. Give the arrays descriptive names. Calculate ASL and ASW for each book. Calculate Reading Ease Score and Grade Level for each book. This data must be stored in 2 new arrays

  What is probability that account will have insufficient fund

What is the probability that the account will have insufficient funds to pay claims at some point during the year - what should this amount be if the company wants there to only be a 5% chance of having insufficient funds?

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