Starting from:

$30

CS113-Homework 2 Solved

Create a single MATLAB script with each problem below as a separate section (hint: %%).  

1.  Create a new script  

2.  Create a comment section at the top with your name, date, HW#, class, etc.  

3.  The first script commands should erase all the workspace data, command window output, and close all figures.  

4.  Create separate sections (%% ) for each problem  

Problem 1:  

Create another section to do the following. Add a comment at the end of each line detailing what each line does. Make sure command outputs are not suppressed so outputs are published in your final document (as well as to the command window).  a. Create the matrix  

20 4 2 6

𝐴=6 37 2 3

8 5 9 9

b.  assign the first row of A to a vector called x1  

c.   assign the last 2 rows of A to an array called y  

d.  assign the even-numbered columns of A to an array called B  

e.   assign the transpose of A (i.e. turns it into a 4-by-3 array) to C  

f.    compute the reciprocal of each element of A  

g.  change the number in column 2, row 3 of A to 100.

 

 

Problem 2: 

Consider the array A, Compute the array B by computing the square roots of all the elements of A whose value is no less than 0 and adding 50 to each element that is negative

  


 

Problem 3.  

Create two plots 𝑦1 and 𝑦2 in a single figure with the following expressions

𝒚𝟏 =𝟐𝒙+𝟓 𝒚𝟐 =𝒙𝟐−𝟑𝒙

where −𝟑≤𝒙≤𝟑. Please set the x axis limit to be within [-3, 3] and y axis limit to be within [-5,20]. Use legend to show each plot.   

Problem 4.  

More products