Question: MATLAB HOMEWORK 1 For all the homework, Copy your script; plot for the 1 st problem and output from the command window for the 2nd
MATLAB HOMEWORK 1
For all the homework, Copy your script; plot for the 1 st problem and output from the command window for the 2nd problem; and paste in the word file/ Submit as word/ pdf.
1. Try plotting the following sine function and cosine function of x as below. Note that x is simply a vector from 0 to 20 in increments of 0.05.
(a) Plot two functions on the same graph. (Either Use the hold command to do this, type help hold for details.) or just the same way as described in the lecture. Use a green solid line at each data point for one function and a black dotted line for the second function. (Use the help command on plot for more info.) Add legend, label your axes and title your graph.
Now add another plot, with has the twice as value in the output than the first function. (2sin(x))
(b) Plot all the three functions (sin(x), cos(x) and 2sin(x)) but one below the other in the same figure window. (Use the subplot command.)
2. A matrix M is given as M = [2 1 7 4 8 10 3 2 5 9]; Write a script that replaces all entries smaller than 4 in a matrix with 0; such that [2 1 7 4 8 10 3 2 5 9] becomes [0 0 7 4 8 10 0 0 5 9]) Hint : Use if-else statement inside a for loop. Your iteration size should be similar to the length of the matrix size.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
