FOR Prof_JHAAAAAAAA

0 comments

Exercise 1: You need to use a period preceding any matrix operations. Remember that +,-,*, /, ^ are all considered matrix operations in MATLAB. Thus, if you declare a row vector x = 0:pi/4:5*pi/4, then cos(x) is a row vector as well with the same dimensions as x. So cos(xautomatically inherits the dimensions of x. This is a very important concept moving on. So if we try to multiply x*cos(x), we will get an error because we are multiplying a row vector by a row vector. From Linear Algebra, we know we cannot do this. We can only multiply row vectors by column vectors and vice versa. Therefore, we need to input a period preceding the matrix operators * to indicate that we want to multiply each element of the row vectors componentwise, i.e., we type x.*cos(x). We use the period (or dot) preceding matrix operators when we are dealing with functions. 

Exercise 2: See page 3 of the protocol. 

Exercise 3: Remember, if we wish to plot cos(x) vs x, we must first declare the row vector x prior to creating the row vector cos(x) since cos(x) depends on x. If we declare cos(x) first, then MATLAB will use the present value of x saved in the workspace. This may be some x that was declared in a previous problem and NOT the same x we want to use now. 

Exercise 5: You NEED to create a function + function M-file. See page 5 of the protocol. Most the code is given to you, just copy and paste it into a new script file and replace all “??” with the appropriate code. 

Exercise 6: Make sure you clear your function from the workspace as stated in part (b). I will mark off points for that. Also, make sure you invoke your function in the command window as stated in the question. For part (b), you need to write a function M-file (NOT in the command window) and invoke the function M-file in the command window.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}