Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

MATLAB Workshop #3 Before you begin your work, save this file as Workshop_3_My_Name to your preferred folder. This will be the file that you submit

MATLAB

Workshop #3

  • Before you begin your work, save this file as Workshop_3_My_Name to your preferred folder. This will be the file that you submit for your assignment, after you have completed your edits.
  • Follow the directions for each task. Below each description, there will be a place holder for you to enter your code.
  • It will be easiest to clear your workspace before beginnging. You will be asked several times to check your workspace and count the number of certain variables. If other variables already exist, this step may be confusing. You can clear your workspace by using the clear command in the command window.
  • This workshop uses Matlab functions. You can use Matlab help and documentation for further info and examples of these. You can access the documentation from the top toolbar.
  • Upload this file, Workshop_3_My_Name.mlx, to the assignment on Canvas. ***Remember to save this file early and often as you enter code***

Task #1:

Generate the three vectors below using the colon : operator

  1. A row-vector named rowVec1 with the values 1 through 32, ex [ 1 2 3 ... 32 ]
  2. A row-vector named rowVec2 with the values 40 through 9 decreasing, ex [40 39 38 ... 9]
  3. A row-vector named rowVec3 with the values 1 through 249 increasing by 8, ex [ 1, 9, 17... 249]

% For this task and all others,

% click within this coding area to begin typing

Task #2:

Generate the three column vectors below. To generate a column vector, you can separate elements by semi-colons ; or use the colon : operator combined with transpose operator ' . Refer to class presentation for examples.

  1. A column-vector named colVec1 with the values 1 through 16, ex [ 1 2 3 ... 16 ]
  2. A column-vector named colVec2 with the values 100 through 70 decreasing by 2, ex [100 98 96 ... 70]
  3. A column-vector named colVec3 with the values -8 through 37 increasing by 3, ex [ -8 -5 -2 ... 37]

% Add code for task here

Checkpoint:

After completing Task #1 and Task #2, you should now have 3 row vectors and 3 column vectors. Run this script by clicking the Run button on the right-hand side of the tool bar above. Your workspace will now populate with the vectors that were generated from your code above. You can now verify that you have generated the expected variables. Also, ensure that all of the column-vectors contain the same number of elements, and all of the row-vectors contain the same number of elements.

Task #3:

Generate one more column vector, colVec4, and one more row vector, rowVec4, both using the linspace function. This function will generate an evenly spaced group of numbers based upon the input arguments. See the examples in the class presentation or use the Matlab documentation for help.

  • colVec4 should be an evenly spaced column-vector between -4 and pi with 16 elements. You will need to use the transpose operator ' to convert the result of the linspace function from row to column
  • rowVec4 should be an evenly spaced row-vector between 400 and 410 with 32 elements.

% Add code for task here

Task #4:

Create a new row-vector called maxRows which will store the maximum values of all row-vectors, rowVec1, rowVec2, rowVec3, and rowVec4 in that order. Use the max function to return the maximum values from each of these vectors. Note that maxRows will be a row vector with 4 elements.

% Add code for task here

Task #5:

Create a new row-vector called minCols which will store the minimum values of all column-vectors, colVec1, colVec2, colVec3, and colVec4 in that order. Use the min function to return the minimum values from each of these vectors. Note that minCols will be a row vector with 4 elements.

% Add code for task here

Checkpoint:

After completing Tasks #1 through #5, you should now have 6 row-vectors and 4 column-vectors. Try re-running this script and checking your workspace. You can also type the who or whos command in the command window to see printed information about the variables in your workspace. Note that a row-vector will have dimensions 1 x n where n is some value >= 1, and a column vector will have dimensions n x 1 where n is some value >= 1.

Task #6:

Remove the middle 8 elements, index 5 through 12, from every column vector. You will need to do two things in order to complete this:

  1. Use an index-vector to reference the middle 8 elements from the column vectors. For example, v( [ 1:3 ] ) will index the first 3 elements of a vector, v.
  2. Set that group of elements equal to an empty vector, [ ]. This will replace the 8 elements with none.

Examples for how to "delete" elements from a vector are also in the class presentation.

% Add code for task here

Task #7:

Find the sum of the products of all 4 column vectors. You can first find the products of the elements of each of the column vectors using the prod function. Add those 4 product values together and save in a variable called columnsSum. This will be a large number.

% Add code for task here

Task #8:

Using the diff function, generate a row-vector representing the value differences in rowVec2, and save it to the variable diffRV2. You can go to the code above or your workspace to remind yourself of the values within rowVec2. Because the elements in this vector are evenly spaced, what will the differences between each element be? Also, remember that the diff function will produce a vector that is one less than the length of the original. Optional: Run the diff function again on diffRV2. What are you expecting the values to be?

% Add code for task here

Task #9:

Concatenate all column vectors vertically, and save to the variable allColumns. Because all 4 column vectors are now 8 elements in length, allColumns should be a 32 x 1 vector. You can use semi-colon notation to combine vectors vertically. For example, if I have two column vectors a and b, I can concatenate them vertically like so: [ a; b ]

% Add code for task here

Checkpoint:

After completing Tasks #1 through #9, you should now have 13 variables in your workspace.

Task #10:

Add the elements of the row-vectors rowVec1, rowVec2r, rowVec3, and rowVec4 together in-line by using the + operator, and save the the variable rowSums. For example, if I have a vector a = [ 1 2 3 ] and vector b = [ 1 1 1 ], then a + b would equal [ 2 3 4 ].

% Add code for task here

Task #11:

Find the squareroot of every element in rowSums and save to the variable sqrtRowSums. You can use the sqrt function to do this, with rowSums as the function argument.

% Add code for task here

I JUST NEED HELP WITH TASK 9 PLEASE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students explore these related Databases questions