Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I posted this question and received a two codes and was wondering if anyone could help me find a code that would work as a

I posted this question and received a two codes and was wondering if anyone could help me find a code that would work as a f.95 file in Fortran Eclipse:

When given a set of data that looks like a line, engineers often want to find the y = m x + b line that best fits the data. In other words, when given a list of x values and a list of corresponding y values, we want to find the slope m and intercept b of the line that comes closest to the x and y data points. This is actually a straightforward process via the method of "least squares", based on minimizing the error between the actual data points and the line one gets using certain values of m and b. We will not cover the derivation here, but the results we will use are below.

Assume that each of our x values is called xi and each of our y values is called yi, so that a single data point is (xi, yi). i goes from 1 to n, which is the number of data points we have. We define average x and y values:

Overview: Our project will be to get a file name from the user, read x and y data from file, display the data at the console, allow the user to remove points from the data, then find the best-fit slope and intercept and send them to the console. In more detail, the project program you write will do the following:

Prompt the user for a file name, which will be stored in a string variable. Use the ADVANCE="no" in the write statement for the prompt to get the prompt and the user's response on the same line.

Read the x and y data from the file and store it in two dynamic, double-precision real arrays. This will require counting the lines in the file to see how many data lines there are and then allocating ME021 Engineering Computing Spring 2018 the arrays. You may assume there will always be two header lines, but there could be any number of data lines.

Set up a loop where:

o The data is shown on the console with a line number for each line. For larger data sets, this may cause the console to scroll, which is fine.

o The user is asked if there is a data point to be removed. If there is, then remove it from the arrays. This may require allocating temporary arrays and allocating the data arrays again. You will need to use the deallocate function before allocating an array that has already been allocated. Choose how to set up the prompts for this to make sense to the user.*

o If the user chose not to remove a data point, exit the loop.

Compute the averages and the best-fit slope and intercept, per the relations above.

Print the resulting equation for the best-fit line in a tidy format that uses a custom real format specification that you think makes for nice output.

Your program should run for any length data file, without assuming a maximum length anywhere. Three data files (xydata1.txt, xydata2.txt, and xydata3.txt) are provided on CatCourses for testing, and your TA may choose to use others as well.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions