|
| Patrice Koehl |
AIX008: Introduction to Data Science: Summer 2022Activity: Getting to know MatlabWith this lab, you will start becoming familiar with the Matlab environment and some of its facilities. You will learn:
Exercise 1: Basic Arithmetic calculations within MatlabEvaluate the following expressions by hand and use Matlab to check the answers:
Exercise 2: assign values to variables; basic operations on arraysTranslate the following math statements into MATLAB commands. For help, the values for the function when x = [1 2 3] are given.
Exercise 3: Control structuresThe Fibonacci sequence
We consider the famous Fibonacci sequence that was originally developed to characterize the population of rabbit. It is define as follows:
For example, starting with n = 1, we get: 1,1,2,3,5,8,13,21 ... Write a Matlab script that computes Fn. Check it for n = 5, 10, and 20.
Exercise 4: PlottingWe want to create a graph of \(y=cos(4x)\) over \([0, \pi]\). To illustrate what happens when there are too few points in the x domain, let us first try a step size of \(\pi/10\).
Exercise 5: Errors in programsThe following Matlab programs contain some elementary programming mistakes. Find the mistake and suggest a solution to each or them.
Exercise 6: graphingBiorhythms
Biorhythms were very popular in the 1960s. They are based on the notion that three sinusoidal cycles influence our lives. The physical cycle has a period of 23 days, the emotional cycle has a period of 28 days, and the intellectual cycles has a period of 33 days. For an individual, the cycles are initialized at birth. The figure below shows my biorhythm, which begins on October 26, 1961, plotted for an eight-week period centered around Wednesday, June 29, 2022.
The following code segment is part of a program that plots a biorhythm for an eight-week period centered on the date June 29, 2022
t0 = datenum('Oct. 26, 1961');
t1 = datenum('June 29, 2022');
t = (t1-28):1:(t1+28);
y1 = 100*sin(2*pi*(t-t0)/23);
y2 = 100*sin(2*pi*(t-t0)/28);
y3 = 100*sin(2*pi*(t-t0)/33);
plot(t,y1,'LineWidth',2);
hold on
plot(t,y2,'LineWidth',2);
plot(t,y3,'LineWidth',2);
|
| Page last modified 19 September 2024 | http://www.cs.ucdavis.edu/~koehl/ |