CMPSC 201-CMPSC201 C++代写
时间:2021-11-30
CMPSC 201 – Fall 2021
Project 5
Due by 11:00 pm on Friday 12/10/21

Worth 50 pts
Take the time to confirm your submission.

Create a single MATLAB *.m file that will complete Problems 1 through 5 Make sure that have
the clear and clc commands at the beginning of your code. Write comments for each problem
before that problem.

Problem 1: Many engineering and scientific relationships can be manipulated to a format of a straight
line, = + , where is the slope of the line and is the intercept. However, because most
measurements have some inherent error, the formula for the line may not be obvious. Therefore, linear
regression may be used to determine the best fit of a line to the measured data. Linear regression uses
the following two equations for calculations of slope and y-intercept where is the number of (, )
data sets that were measured:

=
∑ ∙ ∑ − ∑( ∙ )
(∑ )2 − ∑(2)


− =
∑ − ∙ ∑



The “goodness of fit” of this straight line can be estimated by summing the square of the residuals. The
residual is defined as the difference between the measured value and the calculated value (using
the calculated and − ) for a given . The equation is shown below where is the
measured value and is the calculated value using the and − .

= ∑( − )
2

A lower “goodness of fit” value indicates a better match of the line to the data.

Using the data file named “LinearData.mat”, import the file using the command from Section 2.4.2 of
your textbook (do not use the import wizard!). Your workspace window should show 2 variables: one
named x and one named y. Using the equations above built-in MATLAB functions, calculate the slope
and y-intercept (do not use loops). Create a ycalculated array using the original x values and the slope
and y-intercept you determined. Calculate the “Goodness of Fit” (do not use loops). Plot x vs y and x
vs ycalculated in the same figure. Use different line types, marks and colors for each plot (refer to
Table 4.2 in the textbook)



Problem 2: For this problem you will repeat the analysis of compressive strengths that you did for
Project 4 using MATLAB instead of C++. New data has been stored in the MATLAB file called
“CMPSC201_F21P5b.mat”. Review section 2.4.2 in your textbook and use a command to import this
data into MATLAB (do not use the import wizard!) A variable called CompressP5b should
automatically be created.

Use a MATLAB function to determine the number of formulations (number of rows) and the number
of plants (number of columns). Do not create any arrays that are a subset or transpose of the
variable CompressP5b. Using a single MATLAB command (do not use loops), create a column
vector that contains the minimum compressive strength of each formulation. Using a single MATLAB
command (do not use loops) create a column vector that contains the maximum compressive strength
of each formulation. Using a single MATLAB command (do not use loops) determine the average
compressive strength for each formulation after removing the minimum and maximum compressive
strength for that formulation and store these average values in a column vector.

Create a 2-dimensional array (do not use table command) containing the formulation numbers (1 to
the number of formulations) in the first column, the minimum compressive strengths for each
formulation in the second column, the maximum compressive strengths for each formulation in the
third column, and the average compressive strength for each formulation in the fourth column. Using
this 2-dimensional array and a single fprintf command create output similar to the following:

Formulation __ had a minimum compressive strength of __, a maximum
compressive strength of__, and an average compressive strength of
__.

The formulation number should be displayed as a whole number (no decimal point or places to right of
decimal point), the minimum and maximum strengths should be displayed with 1 digit to the right of
the decimal whereas the average should be displayed with 2 digits to the right of the decimal.


Problem 3: For this problem you will simulate a rock-paper-scissor game in a *.m script file. Using
the menu function allow the user to choose “Rock”, “Paper”, or “Scissors”, 1 should be stored for
“Rock”, 2 should be stored for “Paper” and 3 should be stored for “Scissors”. Generate a random
number of 1, 2, or 3 for the computer’s response. Use if-elseif structure to compare the user’s input to
the random number of the computer’s guess and output a message of who won using the rules:
• Scissors beats (cuts) paper
• Rock beats (breaks) scissors
• Paper beats (covers) rock

The output messages must contain the user’s input and the computer’s choice as “rock”, “paper”, or
“scissors” (do not user numbers 1, 2, or 3) and the result of the game. Some examples are shown
below.

You selected scissor and the computer generated paper, therefore you
won.

You selected paper and the computer generated scissors, therefore
the computer won.

You selected paper and the computer generated paper, therefore it is
a draw.

The last branch of your if/elseif structure should be an else not an elseif.

Problem 4: Complete Problem 5.17 (Problem 17 of Chapter 5 - Compounded Interest) from your
MATLAB textbook. Use the linspace function to create the array for years. You do not need to make
the table. Create variables for P, P0, r and t and prompt the user to enter values for these variables. Do
not create a variable for e but use the appropriate MATLAB function. State which plot produces a
straight line using a comment.



Problem 5: Redo the calculation for the estimate of pi in Lab 10 using a loop to count the number of
points in the circle rather than the MATLAB find and length functions.
essay、essay代写