Question: Please help me write this code using Matlab. I will make sure to upvote. Also, can you explain where to save the functions so that

Please help me write this code using Matlab. I will make sure to upvote. Also, can you explain where to save the functions so that they work as intended upon typing lab1 into the command window. Thanks so much.
Lab 1: Introduction to Matlab
Read sections 1-3 of the Matlab tutorial document. To solve the problems below, you will have to
explore Matlab functionality using the Matlab "help" and you may have to browse through some of
the other tutorials listed in the Resources section. Create a script file called lab1.m, which will hold
all the commands necessary to produce the plots and computations below. Use comments to label
part 2, part 3, etc. Do not forget to move the file to your home directory before you leave the lab.
Vectors
(a) Generate a row vector x of length 25 containing the integers 9,10,11,dots33.
(b) Generate a row vector y containing 25 values, each of whom is a random real number in the
interval 5,8.
(c) Produce a new vector v equal to the sum of the two vectors above.
(d) Plot the vector v in 2.c.
(e) Compute the following:
i.c=xy(element-by-element division, for example (3339) divided by ([1,3,3]) is ([3,1,3]))
ii.d=v4(each element raised to the fourth power)
iii. The dot product of x and y
(f) Plot the odd-index elements of the vector v, that is,v(1),v(3),v(5),dots,v(25).
(g) Plot the elements of the vector v between 10 and 18, that is v(10),v(11),v(12),dots,v(18).
(h) Plot the vectors in 2.a and 2.c on the same plot, using different colors.
(i) Plot all the plots in 2.d-2.g on the same figure.
Hint: help dot, colon, rand, plot, hold, subplot.
Functions
(a) Write a Matlab function named myfun1() that implements the following function:
f(x)={4-|4x|if|x|10ifx-12ifx>1
The function takes a scalar as the input and outputs a scalar (no vectors involved).
(b) Plot the function myfun11) between x=-5 and x=5.
(c) Write a Matlab function myfun2() that takes an input vector of size greater than two and
computes the sum of all the values in the vector that are not prime numbers. (Example: for the
vector 2,-8,3,12, the sum is 4). Apply your function to a vector of length 10 of your choice
and also to the vector x from question 2(a).
(d) Write a function myfun3() that accepts as input arguments a vector x and two scalars m and s
and plots the function
g(x)=1s42exp(-18(x-ms)2)
(e) Using the above function, plot g(x) for a vector x with values from 0 to 5, step 0.05,m=3.6
and s=0.56
Hint: help function, abs, if, fplot, find, isprime, sum.
Complex numbers, Loops
(a) Create a vector of length 10 filled with 10 complex numbers of your choice. Among the values
there should be some purely real and some purely imaginary numbers.
(b) Plot the vectors containing the real parts, imaginary parts, magnitudes, and phases of the 10
complex numbers. Plot them on four different plots on the same figure.
(c) Write a Matlab function myfun4() that takes an input vector and goes through all its compo-
nents, one by one, printing out just the purely imaginary values. Apply your function to the
vector in 4.a
Please help me write this code using Matlab. I

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!