MATLAB for differential equation

Please use format compact and format short before you begin, i.e., type these commands into the command window. format compact condenses the command window output and format short reduces the floating point numbers in MATLAB to 4 decimal places. If problems require answers with more decimal places, you may use format long to get 8 decimal places. If you have ANY doubt about the syntax you are using to invoke a particular elementary function such as exp, cos, sin, etc., then type help elfun into the command window. elfun stands for elementary functions and this command provides a list of elementary functions with their corresponding MATLAB syntax. Remember to use a semicolon “;” to suppress output when the output is not necessary. 

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. 



Make sure that all the codes are not copied from anywhere. 

"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp