Exercise 1[1] Use one of Matlab/Octave/FreeMat (M/O/F, for short) to do the following exercises. Your report must document the steps or M/O/F command used to obtain the result. One way to do this is to cutand-paste from the command window. Try to also document your output in a sensible way. For example, if displaying the contents of some array or vector will take many lines, consider showing an abbreviated set of lines that will give adequate evidence that your solution is correct.
1.1. Create a vector named v of evenly spaced values from 0 to 20 (inclusive) in increments of 1.
1.2. Create a vector named angles of values from 0 to 2π radians in increments of π/10. Note: M/O/F ‘knows’ π natively, so you can form a value like 2π by typing: 2*pi Exercises 1.3 – 1.4 below ask you to use array manipulation methods in M/O/F to accomplish the required task. This means for you to use the abilities that M/O/F has to operate on arrays to get your required results, rather than just retyping individual elements. For example, given the matrix A, where
1 2 3
𝐴𝐴 = 4 5 6
7 8 9
If you were asked to create a vector p consisting of the last row of A, instead of simply typing
𝑝𝑝 = [7 8 9]
you would do something like:
𝑝𝑝 = 𝐴𝐴(3, : )
1.3. Use M/O/F array manipulation methods to build a two-column matrix where the first column consists of the values from Exercise 1.2, and the second column consists of the values from the first column converted into degrees. Do this using the vector v rather than having to re-type the values.
1.4. Use M/O/F array manipulation methods to add a third column to the matrix from Exercise 1.3, such that its elements number off the rows. In other words, 1 will be the top most element in the column, the next element down the column will be 2, and so forth down the column.
1.5. Use M/O/F array manipulation methods to modify the matrix from Exercise 1.4, so that the column you added in Exercise 1.4 becomes the first column instead of the third column.
Exercise 2[2] Use one of M/O/F to:
x=0:0.1:10; y=2*exp(0.2*x);
plot(x,y);
2.1. Enter and run the lines of code to the right. Include the code and the plot in your report
2.2. Take the code you entered, and paste it into an M-file, named exp_plot. Save it on the Desktop, and add the Desktop to the Matlab search path (File | Add path). Show your lab instructor your M-file will run when you type its name to the command prompt.
2.3. Modify the M-file code from 2.1 to annotate the plot with labels for the axes, a title for the plot, and a grid.
Exercise 3[3] Use one of M/O/F to solve the following problems:
3.1. The present value of an annuity (a yearly sum of money) may be computed from the formula:
P = (A/i) [(1 + i)n - 1]/(1 + i)n where A is the annuity (in $/year), i is the nominal yearly interest rate (in decimal form), n is the number of years over which the annuity is paid, and P is the present value in dollars. So, for example, if i = 0.15 (15%), A = $100/year and n = 10 years, then P = $501.88