Homework_4_LinAlg

docx

School

Georgia Institute Of Technology *

*We aren’t endorsed by this school

Course

2016

Subject

Mechanical Engineering

Date

Apr 3, 2024

Type

docx

Pages

5

Uploaded by DukeSquirrelPerson745

Report
Homework 4 Submission Requirements: Please submit to Canvas the following files: 1. A .pdf of this document with the required answer (highlighted yellow) and figures. 2. Your script Homework_4_LastName.m (replace LastName with your last name). 3. Two functions (2) linearRegression.m and rootMeanSquaredError.m 4. The data file Homework_4_Data.mat Part 1: Linear Regression For this homework, you are going to write a function in MATLAB called linearRegression to solve for the coefficients of a line using least-squares regression. You will then use your function to create a regression model for nonlinear data after linearizing it. Remember that we are representing out linear fit in the form: ^ y i = β 0 + β 1 x i a. Hand calculation First you will do a hand calculation on a smaller dataset to check the output of your function. i x y 1 0 0.9351 2 1 2.1181 3 2 2.9242 4 3 3.8890 5 4 4.9154 6 5 5.9427 What are the values of your matrices below? X = [ ¿ ] , X T = [ ¿ ] = [ ¿ ] , y = [ ¿ ] What are the values of your parameters for your linear fit equation? β 1 = ¿ ¿ β 0 = ¿ ¿ ME 2016A– Spring 2023 Copyright Georgia Institute of Technology 1
b. Linear regression MATLAB function Write a function named linearRegression which has the independent variable values, x , and the dependent variable values, y , as inputs and the two regression coefficients, a 1 & a 0 , as the outputs. Calling the function in your MATLAB script would look like: [ beta1, beta0 ] = linearRegression( x, y ); What are the values of the slope, β 1 , and the intercept, β 0 , of the line, ^ y = β 1 x + β 0 ? (Hint: Both should be close to a value of 1 and should agree with your hand calculations): β 1 = ¿ ¿ β 0 = ¿ ¿ c. Plotting the data and model In your script, plot the dataset of x and y as markers in a figure along with your fit line from your linear regression. Copy and paste your figure below making sure to include axis labels that are legible, and a legend that denotes the markers as data and has the equation of the line with the actual coefficient values. Figure here d. Root Mean Squared Error MATLAB function Write a function named rootMeanSquaredError which has the dependent data values, y , and the predicted model values, y pred , as inputs and the model root mean squared error, RMSE , as the output. Calling the function in you MATLAB script would look like: [ RMSE ] = rootMeanSquaredError( y, y_pred ); What is the linear model root mean squared error? (Hint: 0.06 < RMSE < 0.08 ): RMSE = ¿ ¿ Part 2: Linearization of Non-Linear Relationships You are now going to use the dataset contained in Homework_45_Data.mat and determine which model that can be linearized best fits the data. You are going to call your previously created functions to help you do this. ME 2016A– Spring 2023 Copyright Georgia Institute of Technology 2
a. Exponential Equation In class we saw that the exponential equation: y = A e bx Can be linearized by taking the natural logarithm of both sides so that it can be written as: ln ( y ) = ln ( A ) + bx Using your functions linearRegression and rootMeanSquaredError , what are the two coefficients of the of the exponential model for the data and what is the RMSE for model? (Hint: 0.4 < A < 0.6 , 0.1 < b < 0.4 , & 0.01 < RMSE < 0.06 ) A = ¿ ¿ b = ¿ ¿ RMSE = ¿ ¿ b. Power Equation In class we saw that the power equation: y = A x b Can be linearized by taking the base-10 logarithm of both sides so that it can be written as: log ( y ) = log ( A ) + b∙ log ( x ) Using your functions linearRegression and rootMeanSquaredError , what are the two coefficients of the of the power model for the data and what is the RMSE for model? (Hint: 0.4 < A < 0.6 , 0.2 < b < 0.4 , & 0.01 < RMSE < 0.06 ) A = ¿ ¿ b = ¿ ¿ RMSE = ¿ ¿ c. Saturation-Growth-Rate Equation In class we saw that the Saturation-Growth-Rate equation: ME 2016A– Spring 2023 Copyright Georgia Institute of Technology 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
y = Ax x + b Can be linearized by taking the inverse of both sides so that it can be written as: 1 y = 1 A + b A 1 x Using your functions linearRegression and rootMeanSquaredError , what are the two coefficients of the of the Saturation-Growth-Rate model for the data and what is the RMSE for model? (Hint: 0.9 < A < 1.1 , 0.9 < b < 1.1 , & 0.01 < RMSE < 0.06 ) A = ¿ ¿ b = ¿ ¿ RMSE = ¿ ¿ d. Selecting a Model Based upon your calculation for the error for each of the models, select the model which minimizes the error and create a figure in your script which plots the data as markers and plots a line for the model predicted values from 1 to 5 . Copy and paste your figure below making sure to include axis labels that are legible, and a legend denotes the markers as data and has the equation of the line with the actual coefficient values. Figure here Part 3: Polynomial Regression For this part you are going to derive the equations to determine the coefficients of a polynomial using least-squares regression . You want to create a 2 nd order model so that the y-intercept is always equal to zero: ^ y = β 2 x 2 + β 1 x a. Solving for the coefficients In MATLAB solve for the coefficients using the dataset from Homework_4_Data.mat . (Hint: 0.4 < a 1 < 0.6 & 0.07 < a 2 0.05 ) β 1 = ¿ ¿ β 2 = ¿ ¿ b. Evaluating the model ME 2016A– Spring 2023 Copyright Georgia Institute of Technology 4
What is the RMSE for the 2 nd order model? (Hint: 0.05 < RMSE < 0.07 ) RMSE = ¿ ¿ c. Plotting the model and data Create a figure in your script which plots the data as markers and plots a line for the model predicted values from 1 to 5 . Copy and paste your figure below making sure to include axis labels that are legible, and a legend denotes the markers as data and has the equation of the line with the actual coefficient values. Figure here ME 2016A– Spring 2023 Copyright Georgia Institute of Technology 5