Engr 160 Homework Assignment
Due: Thursday, Nov. 4
The purpose of this program is to use the method of least squares (linear regression) to calculate the m, b and r values for a given set of data points. The given data represents information about the volume of water through a culvert, as a function of the height of the water in the culvert.
Program requirements:
- Use a main program and a Subroutine subprogram.
- In the main program, read from the given file (LeastSqrs.txt): on line 1 of the file, read a number which equals the number of data pairs, n (n will never be more than 100); then starting on line 2 of the file the data pairs are listed, (x, y), one per line. Read the data pairs into one-dimensional arrays (one array will contain the x values and the other the y values).
- In the main program, ask the user if they want you to calculate the regression equation for a linear, exponential or power situation.
- Based on the users’ response, calculate and send to the Subroutine the correct form of the x and y values (you may need Lny, etc.).
- In the main program, output to the screen the m, b and r values that are returned from the Subroutine, with the m and b values displayed in the form of the correct general equation (Linear, Exponential or Power).
- Use only ONE Subroutine to calculate the m, b and r values using the Method of Least Squares to do Linear Regression (equations on back of sheet).
- In the main program output the Linear, Exponential or Power equation with the calculated values of m and b inserted in the equations. Also output the r values.
Presentation requirements:
- Create a Word document as the complete solution.
- No complete write-up required – Solution ONLY
- In the Solution include: flowcharts, copy of the computer code, a copy of your output (MsgBoxes) and a Command Button to use to run the program.
- Run your program for all three cases; analyze the output values and determine whether a linear, exponential or power equation best fits the data. In the write-up, clearly indicate which is better and why.
- Two flowcharts will be needed (one for the main program and one for the subprogram).
Submission requirements:
- Submit your Word document electronically to the folder for your section.
- Name your Word file as follows: Number_LastName_FirstName LeastSqrs.docm
- Submit a printout of your Word file in class on the due date.
Notes about the LeastSqrs.txt input file:
- On line one, read the value of n (the count of data pair in the file).
- Starting on line two, the data is given as X, Y
Linear Regression:
Exponential Regression:
x values = x
y values = Ln(y)
b = Ln(b)
Power Regression:
x values = Ln(x)
y values = Ln(y)
b = Ln(b)