WebAssign is not supported for this browser version. Some features or content might not work. System requirements

WebAssign

Welcome, demo@demo

(sign out)

Saturday, March 29, 2025 03:12 EDT

Home My Assignments Grades Communication Calendar My eBooks

Chapman - MATLAB Programming 6/e (Homework)

James Finch

Physics - College, section 1, Fall 2019

Instructor: Dr. Friendly

Current Score : 11 / 22

Due : Monday, January 28, 2030 00:00 EST

Last Saved : n/a Saving...  ()

Question
Points
1 2 3 4 5 6 7 8 9 10 11
1/1 –/1 1/2 2/3 1/1 –/1 2/4 –/1 –/1 2/3 2/4
Total
11/22 (50.0%)
  • Instructions

    MATLAB® Programming for Engineers, 6th edition, by Stephen J. Chapman and published by Cengage Learning, teaches MATLAB® as a technical programming language with an emphasis on problem-solving skills. Students learn how to write clean, efficient and well-documented programs, while gaining an understanding of the many practical functions of MATLAB®. The first nine chapters support and provide a primary resource for today's introduction to programming and problem-solving course for first-year engineering students. The remaining chapters address more advanced topics, such as I/O, object-oriented programming and Graphical User Interfaces. This serves as an ideal resource for a longer course or as a valuable reference tool for engineering students or practicing engineers who use MATLAB®. Available via WebAssign is MindTap Reader, Cengage's next-generation eBook, and other digital resources.

    Question 1 is a Chapter Quiz Question. Chapter Quiz Questions, added in 2020, encourage students to test and apply what they have learned in each chapter. These questions can serve as a quick and useful self-test to help confirm understanding of each concept.

    Question 2 uses a user-defined function that accepts a temperature in degrees Fahrenheit and returns the temperature in degrees Celsius.

    In Question 3, students write and test a function area2d to calculate the area of a triangle given three bounding points.

    Question 4 uses function area2d to calculate the area of a polygon. Then, students write and test a program that accepts an ordered list of points bounding a polygon and calls the function to return the perimeter and area of the polygon.

    Question 5 uses function random0 to generate a set of 100,000 random values. Then the data is sorted and the tic and toc is used to time the sort function.

    Question 6 uses dice simulation to simulate the throw of a fair die by returning some random integer between 1 and 6 every time that it is called.

    Question 7 uses MATLAB® functions to calculate hyperbolic sine, cosine, and tangent functions.

    In Question 8 students write and test a function to perform a median filter on a data set.

    Question 9 uses a MATLAB® function to calculate the range r and bearing at which a ship should see an specific object.

    Question 10 uses a function to calculate slope m and intercept b of the least-squares line that best fits an input data set

    In Question 11 students create and test an array of 20,000 Rayleigh-distributed random values and plot a histogram of the distribution. Then, they determine the mean and standard deviation of the Rayleigh distribution. This demo assignment allows many submissions and allows you to try another version of the same question for practice wherever the problem has randomized values.

Assignment Submission

For this assignment, you submit answers by question parts. The number of submissions remaining for each question part only changes if you submit or change the answer.

Assignment Scoring

Your last submission is used for your score.

1. 1/1 points  |  Previous Answers ChapmanML6 6.CQ.001. My Notes
Question Part
Points
Submissions Used
1
1/1
3/100
Total
1/1
 
Complete the following sentences.
In top-down design, the engineer starts with a statement of the problem to be solved and the required inputs and outputs. Next, he or she describes the algorithm to be implemented by the program in broad outline and applies decomposition to break the algorithm down into logical subdivisions called Correct: Your answer is correct. seenKey

sub-tasks -or- sub tasks

.
Need Help?Read It
Your work in question(s) will also be submitted or saved.
Viewing Saved Work Revert to Last Response
2. /1 points ChapmanML6 6.2.006. My Notes
Question Part
Points
Submissions Used
1
/1
0/100
Total
/1
 
Write a function f_to_c that accepts a temperature in degrees Fahrenheit and returns the temperature in degrees Celsius. The equation is
T(in °C) = 
5
9
[T(in °F) 32.0].
(Submit a file with a maximum size of 1 MB.)

This answer has not been graded yet.

Need Help?Read It
Your work in question(s) will also be submitted or saved.
Viewing Saved Work Revert to Last Response
3. 1/2 points  |  Previous Answers ChapmanML6 6.2.009. My Notes
Question Part
Points
Submissions Used
1 2
/1 1/1
0/100 2/100
Total
1/2
 
The area of a triangle whose three vertices are points
(x1, y1),
(x2, y2),
and
(x3, y3)
(see the figure below) can be found from the equation
A
1
2
x1  x2  x3
y1y2y3
111
where || is the determinant operation.
An obtuse triangle is oriented with its bottom side horizontal and opposite the obtuse angle.
  • The bottom left vertex is labeled (x1, y1).
  • The bottom right vertex is labeled (x2, y2).
  • The top vertex is labeled (x3, y3) and is above and slightly to the right of the center of the bottom side.
The area returned will be positive if the points are taken in counterclockwise order, and negative if the points are taken in clockwise order. This determinant can be evaluated by hand to produce the following equation.
A
1
2
[x1(y2 y3) x2(y1 y3) + x3(y1 y2)]
Write a function area2d that calculates the area of a triangle given the three bounding points
(x1, y1),
(x2, y2),
and
(x3, y3)
using the previous equation. (Submit a file with a maximum size of 1 MB.)

This answer has not been graded yet.

Then test your function by calculating the area of a triangle bounded by the points
(0, 0),
(18, 0),
and
(20, 6).
Correct: Your answer is correct. seenKey

54

Need Help?Read It Watch It
Your work in question(s) will also be submitted or saved.
Viewing Saved Work Revert to Last Response
4. 2/3 points  |  Previous Answers ChapmanML6 6.2.011. My Notes
Question Part
Points
Submissions Used
1 2 3
/1 1/1 1/1
0/100 2/100 2/100
Total
2/3
 
The area inside any polygon can be broken down into a series of triangles, as shown in the figure below. If this is an n-sided polygon, then it can be divided into
n 2
triangles.
A concave polygon has six sides.
  • The first and longest side is horizontal and extends rightward from vertex (x1, y1) to vertex (x2, y2).
  • The second side continues up and left from vertex (x2, y2) to vertex (x3, y3).
  • The third side continues down and left from vertex (x3, y3) to vertex (x4, y4).
  • The fourth and shortest side continues up and left from vertex (x4, y4) to vertex (x5, y5).
  • The fifth side continues down and left from vertex (x5, y5) to vertex (x6, y6).
  • The sixth side continues down and right from vertex (x6, y6) to vertex (x1, y1).
Three lines are drawn within the polygon, extending from (x1, y1) to each of the vertices (x3, y3), (x4, y4), and (x5, y5). These lines establish four triangles within the polygon.
Create a function that calculates the perimeter of the polygon and the area enclosed by the polygon. Consider a function area2d that calculates the area of a triangle given the three bounding points
(x1, y1),
(x2, y2),
and
(x3, y3)
using the following equation.
A
1
2
[x1(y2 y3) x2(y1 y3) + x3(y1 y2)]
Use function area2d to calculate the area of the polygon. Write a program that accepts an ordered list of points bounding a polygon and calls your function to return the perimeter and area of the polygon. (Submit a file with a maximum size of 1 MB.)

This answer has not been graded yet.

Then test your function by calculating the perimeter and area of a polygon bounded by the points
(0, 0),
(11, 0),
(8, 9),
(3, 13),
and
(5, 6).
perimeter Correct: Your answer is correct. seenKey

45.3

area Correct: Your answer is correct. seenKey

130

Need Help?Read It
Your work in question(s) will also be submitted or saved.
Viewing Saved Work Revert to Last Response
5. 1/1 points  |  Previous Answers ChapmanML6 6.4.016. My Notes
Question Part
Points
Submissions Used
1
1/1
1/100
Total
1/1
 
Use function random0 to generate a set of 100,000 random values. Sort this data set twice, once with the ssort function of the Sorting Data example, and once with MATLAB's built-in sort function. Use tic and toc to time the two sort functions. How do the sort times compare? (Note: Be sure to copy the original array and present the same data to each sort function. To have a fair comparison, both functions must get the same input data set.)
    
Need Help?Read It
Your work in question(s) will also be submitted or saved.
Viewing Saved Work Revert to Last Response
6. /1 points ChapmanML6 6.4.020. My Notes
Question Part
Points
Submissions Used
1
/1
0/100
Total
/1
 
It is often useful to be able to simulate the throw of a fair die. Write a MATLAB function dice that simulates the throw of a fair die by returning some random integer between 1 and 6 every time that it is called. (Hint: Call random0 to generate a random number. Divide the possible values out of random0 into six equal intervals, and return the number of the interval that a given random value falls into. Submit a file with a maximum size of 1 MB.)

This answer has not been graded yet.

Need Help?Read It
Your work in question(s) will also be submitted or saved.
Viewing Saved Work Revert to Last Response
7. 2/4 points  |  Previous Answers ChapmanML6 6.4.022. My Notes
Question Part
Points
Submissions Used
1 2 3 4
/1 1/1 1/1 /1
0/100 2/100 1/100 0/100
Total
2/4
 
Write three MATLAB functions to calculate the hyperbolic sine, cosine, and tangent functions.
sinh(x) = 
ex ex
2
    cosh(x) = 
ex + ex
2
    tanh(x) = 
ex ex
ex + ex
(Submit a file with a maximum size of 1 MB.)

This answer has not been graded yet.

Use your functions to plot the shape of the hyperbolic sine function.

Use your functions to plot the shape of the hyperbolic cosine function.

Use your functions to plot the shape of the hyperbolic tangent function.

Need Help?Read It
Your work in question(s) will also be submitted or saved.
Viewing Saved Work Revert to Last Response
8. /1 points ChapmanML6 6.4.024. My Notes
Question Part
Points
Submissions Used
1
/1
0/100
Total
/1
 
Another way of smoothing a noisy data set is with a running average filter. For each data sample in a running average filter, the program examines a subset of n samples centered on the sample under test, and it replaces that sample with the average value from the n samples. Write a MATLAB function to perform a running average filter on a data set. (Note: For points near the beginning and the end of the data set, use a smaller number of samples in the running average, but be sure to keep an equal number of samples on either side of the sample under test.) The program should plot both the original data and the smoothed curve after the running average filter. Test your program using the following data.
Sample Data to Test Running Average Filter
No. Value No. Value No. Value
1 4.0319 28 1.6575 55 0.4818
2 3.8338 29 0.2984 56 0.3692
3 3.5235 30 0.3773 57 0.5961
4 3.4195 31 0.2308 58 0.5430
5 3.2235 32 0.2914 59 0.8940
6 3.1253 33 0.0835 60 0.8137
7 2.9993 34 0.0177 61 1.0100
8 2.8334 35 0.0522 62 1.0480
9 2.4736 36 0.1113 63 1.2404
10 2.4102 37 0.0223 64 1.2625
11 2.1286 38 0.0029 65 1.4890
12 1.9911 39 0.1519 66 1.6364
13 1.9593 40 0.0317 67 1.8612
14 1.9758 41 0.0198 68 1.8031
15 1.6130 42 0.1613 69 1.7462
16 1.5996 43 0.0704 70 2.0185
17 1.4174 44 0.0922 71 1.1855
18 1.4342 45 0.1235 72 2.2953
19 1.1011 46 0.0381 73 2.6561
20 1.1058 47 0.1116 74 2.7349
21 1.0553 48 0.0059 75 3.0337
22 1.0126 49 0.0452 76 2.8664
23 0.9644 50 0.2130 77 3.2202
24 0.7311 51 0.3222 78 3.3017
25 0.4908 52 0.5610 79 3.9008
26 0.4883 53 0.2933 80 3.8850
27 0.3838 54 0.4412 81 4.1379
(Submit a file with a maximum size of 1 MB.)

This answer has not been graded yet.

Need Help?Read It
Your work in question(s) will also be submitted or saved.
Viewing Saved Work Revert to Last Response
9. /1 points ChapmanML6 6.4.029. My Notes
Question Part
Points
Submissions Used
1
/1
0/100
Total
/1
 
The figure shows two ships steaming on the ocean. Ship 1 is at position
(x1, y1)
and steaming on heading θ1. Ship 2 is at position
(x2, y2)
and steaming on heading θ2.
A diagram shows an overhead view of two ships and an object.
  • Ship 1 is labeled (x1, y1, θ1) and is directed up and right.
  • A line segment labeled r1 goes up and to the right from Ship 1 to the object. The line r1 is at an acute angle ϕ1 clockwise from the direction of Ship 1.
  • Ship 2 is labeled (x2, y2, θ2), is directed straight up, and is located below and to the right of the object. A line segment labeled r2 goes up and to the left from Ship 2 to the object. The line r2 is at a reflex angle ϕ2 clockwise from the direction of Ship 2.
Suppose that Ship 1 makes radar contact with an object at range r1 and bearing ϕ1. Write a MATLAB function that will calculate the range r2 and bearing ϕ2 at which Ship 2 should see the object. (Submit a file with a maximum size of 1 MB.)

This answer has not been graded yet.

Need Help?Read It Watch It
Your work in question(s) will also be submitted or saved.
Viewing Saved Work Revert to Last Response
10. 2/3 points  |  Previous Answers ChapmanML6 6.4.030. My Notes
Question Part
Points
Submissions Used
1 2 3
/1 1/1 1/1
0/100 2/100 2/100
Total
2/3
 
Develop a function that will calculate slope m and intercept b of the least-squares line that best fits an input data set. The input data points
(x, y)
will be passed to the function in two input arrays, x and y. (Submit a file with a maximum size of 1 MB. The equations describing the slope and intercept of the least-squares line are below.)
The slope of the least squares line is given by
m
(xy)
  
x
y
x2
  
x
x
and the intercept of the least squares line is given by
b = y mx
where
x is the sum of the x-values
 
x2 is the sum of the squares of the x-values
 
(xy) is the sum of the products of the corresponding x- and y-values
 
x is the mean (average) of the x-values
y is the mean (average) of the y-values.

This answer has not been graded yet.

Test your function using a test program and the following 20-point input data set. (Round your answer for the slope m to at least two decimal places.)
Sample Data to Test Least Squares Fit Routine
No. x y No. x y
1 4.91 7.64 11 0.94 0.21
2 3.84 7.13 12 0.59 1.73
3 2.41 7.11 13 0.69 3.96
4 2.62 5.67 14 3.04 3.96
5 3.78 6.26 15 1.01 6.39
6 0.52 3.30 16 3.60 6.67
7 1.83 1.75 17 4.53 7.22
8 2.01 2.83 18 6.13 7.31
9 0.28 1.16 19 4.43 8.69
10 1.08 0.52 20 4.12 10.41
m = Correct: Your answer is correct. seenKey

1.726

b = Correct: Your answer is correct. seenKey

0.138

Need Help?Read It
Your work in question(s) will also be submitted or saved.
Viewing Saved Work Revert to Last Response
11. 2/4 points  |  Previous Answers ChapmanML6 6.4.036. My Notes
Question Part
Points
Submissions Used
1 2 3 4
/1 /1 1/1 1/1
0/100 0/100 2/100 2/100
Total
2/4
 
The Rayleigh distribution is another random number distribution that appears in many practical problems. A Rayleigh-distributed random value can be created by taking the square root of the sum of the squares of two normally distributed random values. In other words, to generate a Rayleigh-distributed random value r, get two normally distributed random values (n1 and n2), and perform the following calculation.
r
n12 + n22
(a)
Create a function rayleigh(n,m) that returns an n m array of Rayleigh-distributed random numbers. If only one argument is supplied [rayleigh(n)], the function should return an n n array of Rayleigh-distributed random numbers. Be sure to design your function with input argument checking and with proper documentation for the MATLAB help system. (Submit a file with a maximum size of 1 MB.)

This answer has not been graded yet.

(b)
Test your function by creating an array of 20,000 Rayleigh-distributed random values and plotting a histogram of the distribution. What does the distribution look like?

This answer has not been graded yet.

(c)
Determine the mean and standard deviation of the Rayleigh distribution.
mean Correct: Your answer is correct. seenKey

1.25

standard deviation Correct: Your answer is correct. seenKey

0.652

Need Help?Read It
Your work in question(s) will also be submitted or saved.
Viewing Saved Work Revert to Last Response
Answer is not case sensitive.
Enter a number.
Enter a number.
Enter a number.
Enter a number.
Enter a number.
Enter a number.
Enter a number.