Ask MATLAB Expert

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

MATLAB, Engineering

  • Category:- MATLAB
  • Reference No.:- M91761106

Have any Question?


Related Questions in MATLAB

Assignment - matlab programmingusing appropriate matlab

Assignment - MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

Assignment details -need to write a code for connecting

Assignment Details - Need to write a code for connecting segments (Lines) a special case of TSP. The problem is to connect lines in 2d/ 3d space with path obstructions. Can you help me write the code for this? Hope you m ...

Assignment -we have daily gridded rainfall data of 40 years

Assignment - We have daily gridded rainfall data of 40 years and structure of the dataset is like below; Lat = [6.5:0.25:38.5]; Lon = [66.5:0.25:100]; Rainfall (135x129x365x40) (Lon, Lat, days, years). Now, we looking fo ...

Question a safe prime is a prime number that can be written

Question : A safe prime is a prime number that can be written in the form 2p + 1 where p is also a prime number. Write a MATLAB script file that finds and displays all safe primes between 1 and 1000.

Question - verify the attached paper with matlab and get

Question - Verify the attached paper with matlab and get all the results in the paper and explain step by step the matlab code. Paper - Improving Massive MIMO Belief Propagation Detector with Deep Neural Network. Attachm ...

Assignment -data is given on which want to do computational

Assignment - Data is given on which want to do computational production planning using Metaheuristic MATLAB Programming: 1) Ant Colony Algorithm on both Partial and Total Flexible Problem. 2) Bee Algorithm on both Partia ...

What comparison of means test was used to answer the

What comparison of means test was used to answer the question

Question 1 manipulate spectral imagehyperspectral images

Question 1. Manipulate spectral image Hyperspectral images can be seen as a generalisation of normal colour images such as RGB images. In a normal RGB colour image, there are 3 channels, i.e. channels for red colour, gre ...

Assignment -matlab codes and simulated model in

Assignment - Matlab codes and simulated model in simulink/matlab and truetime. 1. Matlab codes and simulink model for pid controller optimization using particle swarm optimization (PSO) my plant is integer order 1000/(s^ ...

Assignment matlab programmingusing appropriate matlab

Assignment: MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As