Distance (ft):::Deflection (in) 174.33:::30.59 452.04:::21.15 67.23:::33.83 529.83:::21.54 35.62:::36.66 385.66:::29.5 92.37:::32.16 148.74:::30.2 57.36:::33.68 727.9:::12.85 329.03:::26.35...

1 answer below »
See attached files


Distance (ft):::Deflection (in) 174.33:::30.59 452.04:::21.15 67.23:::33.83 529.83:::21.54 35.62:::36.66 385.66:::29.5 92.37:::32.16 148.74:::30.2 57.36:::33.68 727.9:::12.85 329.03:::26.35 22.12:::37.58 280.72:::27.56 108.26:::32.76 13.74:::41.25 16.1:::37.29 41.75:::36.43 18.87:::35.66 25.93:::33.51 11.72:::39.29 204.34:::35.78 239.5:::33.85 1000.0:::10.48 48.94:::39.27 10.0:::36.4 30.39:::40.82 621.02:::23.1 78.8:::35.12 853.17:::14.24 126.9:::36.45 Microsoft Word - Homework12.docx ENGR 102 - Homework 12 Problem #1: Linear Regression Many times, it is valuable for us to fit a line to a set of data. Consider the plot below: A number of observations (x,y) were collected and are shown as red circles on the plot above. It is assumed that x and y are linear correlated (i.e. y = b + m*x). Linear regression fits a line (shown in blue with the equation given) to the data such that the distance between the red dots and the line is minimized. Linear regression can be carried by solving the linear system that is shown below. or Note: this is simply the coefficient matrix that consists of a column of 1’s and a column of our independent data (x) and our solution vector that is a column of our dependent data (y). Write a program that will load the data from the file linear.dat located in the week 12 folder. Your program should load the data into numpy arrays and form the coefficient matrix and solution vector as outlined above. The program should use the appropriate linear algebra solver in numpy to solve for the intercept of the line, b, and the slope of the line, m. Your program should create a figure that contains a scatter plot the data from linear.dat as red squares and a fitted line as a green dash-dot line. The plot should contain gridlines, axis labels, a title, a legend, and the equation of the line similar to what is shown in the example above. Submit your python file and output file: [Fi-last name]_[sec#]_hmk12_p1.py y1 y2 ! yn ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ = b b ! b mx1 mx2 ! mxn ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ 1 1 ! 1 x1 x2 ! xn ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ b m ⎡ ⎣ ⎢ ⎤ ⎦ ⎥= y1 y2 ! yn ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥
Answered Same DayNov 11, 2021

Answer To: Distance (ft):::Deflection (in) 174.33:::30.59 452.04:::21.15 67.23:::33.83 529.83:::21.54...

Vicky answered on Nov 11 2021
150 Votes
import numpy as np
import matplotlib.pyplot as plt
file = open('linear.dat','r').read()
data = []

for i in file.split('\n'):
data.append(i.split(':::'))
data = data[:-1]
X = []
for i in data[1:]:
X.append(i[0])
X = np.array(X).astype(float)
X_mat=np.vstack((np.ones(len(X)),...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here