## Description

**PURPOSE:** To practice plot and FOR loop in conjunction with the IF and BREAK statements; and switch statement.

** **

For each problem, create a MATLAB script file and name it FIRSTNAME_LASTNAME_LAB7_ problemX.m. Put ALL the commands for the required steps in your script file:

- Be sure to clear the display and the memory.
- Display your name.
- Separate and label different steps using comments.

———————————————————————————————————————

%{Class: ENGR15100: Software Tools for EngineersInstructor: Xiaoli Yang Author: [Student’s Name]Assignment: Lab [No.]File Name: LASTNAME_LAB[No.]_problem[No.].mDate: [MM]/[DD]/[YY]%}

%clear screen

clc

%clear workspace

clear

disp(‘Your Name Here’);

disp(”);

disp(‘starting code: ‘);

%Completing lab x

%your source code here%

———————————————————————————————————————

**problem 1 ****(30 points):**

Using what you have learned in the last several labs it is desired to make a plot of the following equation:

The equation is derived from the circuit shown below:

The Y axis variable P is power of the resistor R_{L} which is transferred from a battery modeled as a voltage source V_{TH }equal to 10 V also having and internal heating loss modeled by R_{TH}=20 Ohms .

It is desired to plot the power P on the Y axis in terms of the load resistance R_{L }on the X axis for the purpose of estimating the value of R_{L }which results in a maximum value of P. Assume the input R_{L}, changes from 0 to 40 Ohms with a step size of 0.1 Ohms. Create the plot described above and add a title, the appropriate x and y labels and lastly activate a grid to aid in reading the plot.

**problem 2 ****(30 points):**

Next, use a FOR loop starting at R_{L} =0 having an ohmic step size of 0.001 ohms to find the value of R_{L }which makes power P maximum. You will need to include an appropriate IF statement in your code to determine when the maximum value of P is reached and stop the FOR loop using the BREAK command. Lastly, use FPRINTF command to print out the solution found for the value of R_{L} and the corresponding value of load power P.

**problem 3****(40 points):**

The average monthly precipitation (in.) for Boston and Seattle during 2012 are given in the vectors below (data from the U.S. National Oceanic and Atmospheric Administration).

BOS=[2.67 1.00 1.21 3.09 3.43 4.71 3.88 3.08 4.10 2.62 1.01 5.93]

SEA=[6.83 3.63 7.20 2.68 2.05 2.96 1.04 0.00 0.03 6.71 8.28 6.85]

Where the elements in the vectors are in the order of the months (January, February, etc.) Write your program to answer the following:

- Calculate the total precipitation for the year and monthly average precipitation in each city. Do NOT use MATLAB’s built-in functions sum and mean.
- How many months was the precipitation above the average in each city?
- How many months, and on which months, was the precipitation in Boston lower than the precipitation in Seattle?

** **

**problem 4****(Bonus: 30 points):**

Create a new script file called LASTNAME_LAB6_problem4.m. Again, begin by printing both your name and a title at the beginning of code using the DISP command.

A vector is given by x=[4.5 5 -16.12 21.8 10.1 -16.11 5 14 -3 3 2]. Using conditional statements and loops, write a program that implements “Selection Sort” to rearrange the elements of x in order from the smallest to the largest. Do NOT use MATLAB’s built-in function sort().

** **

**Selection Sort**

Suppose x is an array of n values. We want to sort x in ascending order. That is, x[1] should be the smallest and x[n] should be the largest. The idea of Selection Sort is that we repeatedly find the smallest element in the unsorted part of the array and swap it with the first element in the unsorted part of the array.

** **

** **

**SUBMITTING YOUR LAB:**

Submit your lab by uploading .m file using the Blackboard Assignment feature no later than the date specified.