Of great importance in engineering is a variety of techniques
used to create mathematical models of relationships between
measurements. A very common technique is called the Method of Least
Squares (Linear Regression). This numerical method consists of
determining the equation of the straight line that best fits a set
of data.
The raw data consists of a set of points, each with two measured
coordinate values. For example, one could measure the temperature
and humidity at intervals throughout the day, and then plot them on
a graph. Often, a clear relationship will be evident just by
looking at the data. If the relationship appears to be linear, then
linear regression analysis is appropriate. To determine the
equation of the straight-line model, we find both the slope and the
intercept:
Write a program that uses linear regression to determine the
equation of the straight line that best fits the data shown on the
back of this page. Begin by downloading the input file named
HW10resist.txt containing the values shown there. Your program will
read this file and store the values in two parallel arrays. It will
then analyze the data and output to the console (neatly formatted)
the number of data points, the mean value of both variables, the
equation of the best-fit line, and its R-squared value. Don't
forget to check your work—at least make sure your answers are
reasonable. The following are required:
1) Write a function to load the arrays. Do not hardcode the
number of data points (n) — count them as you load the arrays.
2) Pass the arrays to a second function that will calculate the
slope, y-intercept and Rsquared value of the best-fit straight
line. (This will involve the summations.)
3) Write a third function that will return the average value of
any array passed to it. (Call it twice to obtain Tavg, and
Ravg.)
4) Write a fourth function to output the results to the console.
Be sure to format your results very neatly and very clearly. Make
it look professional:
Joe Schmoe ENGR230 Least Squares
Analyzing data in file HW10resist.txt.
Number of data points: a
Mean value of Temperature (deg. F): a.aa
Mean value of Resistance (Ohms): a.aa
The equation of the best fit line is: y = (a.aa)x + a.aa
The R-squared value is: a.aaaa
The resistance characteristics of a thermistor can be found by
placing it in an oven where its temperature can be varied while its
resistance to electrical current is measured. One such exercise
resulted in the following data:
Temperature(F)
Resistance(Ohms)
299
13580
284
10430
258
7576
240
5328
220
3446
201
2308
182
1578
160
932
139
726
121
416
100
169
Hint: You have a set of summations to do. Do them all in one
loop. Excel’s curve fitting tool may be a good way to check your
answer. Plot the data in Excel then choose:
Chart Tools->Layout->Trendline->More Trendline
Options
Choose Linear Trend and check the boxes for Display Equation on
chart and Display R-squared value on chart. The R-squared value is
the correlation coefficient squared.
11 y= mx + b where ηΣΧΥ; -ΣΑΣ: ηΣ -ΙΣ - ΣΥΣ-ΣΑΣ, ηΣ, -ΙΣ and and the correlation coefficient squared (or R-squared value) is a measure of how good the fit is: ηΣ.y-ΣΑΣ Σ' ΣΑΙ ΗΣΥ -Σ». In these equations, n is the number of data points and (x,y:) are the coordinate values of each data point,
Of great importance in engineering is a variety of techniques used to create mathematical models of relationships betwee
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Of great importance in engineering is a variety of techniques used to create mathematical models of relationships betwee
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!