+ All Categories
Home > Documents > betsymccall.netbetsymccall.net/prof/courses/summer16/aacc/202lab8.docx · Web viewWe use the...

betsymccall.netbetsymccall.net/prof/courses/summer16/aacc/202lab8.docx · Web viewWe use the...

Date post: 14-Aug-2019
Category:
Upload: nguyendiep
View: 212 times
Download: 0 times
Share this document with a friend
3
MAT 202, Lab #8, Summer 2016 Name _____________________________________________ Directions: The labs for this course will require the use of MatLab. Instructions on how to access MatLab can be found under a separate document posted in the course. Use the listed example code to complete the following exercises. Print the resulting MatLab worksheet. Circle and number the solutions to the problems on the printout. Or, copy and paste the contents of the MatLab worksheet into a file, note the problem numbers in the code, to submit the problems electronically. Example Code File: 202lab_ex8.pdf This lab will cover how to solve regression equations in MatLab. We will be working with the dataset shown in the table below. We will take x to be the number of years since 1980. First, we enter the data into MatLab as vectors. We will use row vectors to start to aid graphing. Then we plot the data. MatLab automatically connects the points, which isn’t really what we want, but try to enter your x-values in order to make it appear less messy. Compare to the graph obtained in your calculator. We can imagine this dataset as roughly linear. So we will start by approximating it as a linear equation of the form β 0 +β 1 x=y . The vector corresponding to β 0 has a coefficient of 1 everywhere. We create a vector to represent that. Then we create the A matrix (coefficient matrix) for our calculation. Because the equation is linear, the second column of this matrix is just the x-values. We use the transpose function so that the row vector we used to graph is now the column vector for the matrix.
Transcript
Page 1: betsymccall.netbetsymccall.net/prof/courses/summer16/aacc/202lab8.docx · Web viewWe use the transpose function so that the row vector we used to graph is now the column vector for

MAT 202, Lab #8, Summer 2016 Name _____________________________________________

Directions: The labs for this course will require the use of MatLab. Instructions on how to access MatLab can be found under a separate document posted in the course. Use the listed example code to complete the following exercises. Print the resulting MatLab worksheet. Circle and number the solutions to the problems on the printout. Or, copy and paste the contents of the MatLab worksheet into a file, note the problem numbers in the code, to submit the problems electronically.

Example Code File: 202lab_ex8.pdf

This lab will cover how to solve regression equations in MatLab. We will be working with the dataset shown in the table below.

We will take x to be the number of years since 1980.

First, we enter the data into MatLab as vectors. We will use row vectors to start to aid graphing.

Then we plot the data. MatLab automatically connects the points, which isn’t really what we want, but try to enter your x-values in order to make it appear less messy. Compare to the graph obtained in your calculator. We can imagine this dataset as roughly linear. So we will start by approximating it as a linear equation of the form β0+β1 x= y . The vector corresponding to β0 has a coefficient of 1 everywhere. We create a vector to represent that.

Then we create the A matrix (coefficient matrix) for our calculation. Because the equation is linear, the second column of this matrix is just the x-values. We use the transpose function so that the row vector we used to graph is now the column vector for the matrix.

Next, we calculate the values for our estimates of β0 , β1 by calculating the formula ( AT A )−1 AT y⃗=b⃗. Note that we have to use the transpose on the y⃗ vector also, since we entered it as a row vector and this calculation need the column vector version.

After calculating that b0=13.4 , b1=1.08, we add the graph of the equation y=13.4+1.08 x to the graph of our data. This is a pretty good fit for the graph.

Page 2: betsymccall.netbetsymccall.net/prof/courses/summer16/aacc/202lab8.docx · Web viewWe use the transpose function so that the row vector we used to graph is now the column vector for

What if we think a cubic function might be a better fit? The sample code calculates that result next.

We might be justified in using a model like this with more variables for a larger data set, but since the two leading variables have coefficients which are very close to zero, it doesn’t appear that we are getting that much more accuracy for the number of variables we are using. Therefore, we should probably prefer the linear equation.

For each of the datasets below, calculate the regression equation. Do this by graphing the data first, and then choosing an appropriate equation of best-fit. Graph the resulting equation on the same graph as the data for comparison. Note that for some non-linear equations, you may need to transform one or both variables in order to do the calculation.

1. 3.

2. 4.

Collect all your graphs and code, along with any answers to other questions into a single Word or pdf file for submission. Do no submit matlab files.


Recommended