Matlab Laboratory for September 3

Contents

First look over the following four demonstrations. After you feel you understand the examples, do the assignment at the end. If you finish before the hour is over, show your results to an instructor and begin work on Project 1.

Examples

MATLAB Implementation of Textbook Examples

Assignment:

  1. Write a program that evaluates the function $f(x)=e^x sin{(4x)}$ and save it to a file called myfunction.m. Write it in such a way that it can be applied directly to a matrix. Use this function to plot y=f(x) for x between $-\pi$ and $\pi$. (The MATLAB command pi contains a full decimal expansion. Use it.)On the same axes plot x^2. Be sure to use enough points to get a good plot. Label your axes and make a legend. Output your plot to a file. My Solution
  2. Write a program that takes as its input an integer n. The function should print a table with three columns. The first column should be all the integers k from 1 to n. The second column should be 1/k and the third column sin(k). All three columns should begin with a title line, as in the file format_demo.m. Run the program using n=13 and save your results to a file either by (1) using the diary command, or (2) working in cell mode. You may modify my program format_demo.m to do this. My Solution
  3. Write a program implementing Giordano et al, Section 1.2 problem 2. Produce a MATLAB figure similar to of figure 1.7 on p. 11 and one analogous to figure 11 on p 14. You may use an Excel spreadsheet sheet to enter the data, as I have for example 1, and use the MATLAB command xlread to load it into MATLAB. My Solution and My Excel File