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
- Formatting Demonstration: A function that inputs one variable and outputs one variable as well as demonstrating formatted output
- product_and_sum.m: A function that inputs two variables and outputs two variables.
- Loop demonstration
- Matrix demonstration
- Logistic Map demonstration: This contains a demonstration of the difference between "good" and "bad" outputting. Also, here the same example implemented in Microsoft Excel. Note that it is impossible to check a printout of an excel file for mistakes.
MATLAB Implementation of Textbook Examples
- Giordano et al, Section 1.2 example 1. Download this Excel sheet to run the example.
- Giordano et al, Section 1.2 example 2. Download this Excel sheet to run the example.
- Giordano et al, Section 1.4 example 1.
- Giordano et al, Section 1.4 example 3.
- Fibonacci's Rabbits, which I covered in class
Assignment:
- Write a program that evaluates the function
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
and
. (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 - 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
- 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