Computational Physics EX 3: Regression

Due Feb 5

Regression Formula

Py 200

Write a program that accepts (X,Y) coordinate pairs, plots these pairs , and calculates and plots the linear regression for the best straight line fit.



Even though many types of phenomena obey a linear relationship

y = A x + B

data taken in the real world and plotted on a sheet of graph paper will not lie along a perfect straight line. The task of finding the best straight line is called linear regression. Assume you have a set of data, {(x1,y1), (x2,y2), (x3,y3), (x4,y4) … (xN,yN)}, that you feel fairly certain obeys a linear relationship. You can find the slope and intercept of this best fit from the following formulas:

Regression Formula

The computer is well suited to this type of calculation. First you must get the data into the program. You can use the SGraph object to both store and plot the data. You can then write a Do loop that gets the data from the graph and performs the sums. The calculation of A and B are then trivial.


Build a really useful program. Linear regression is a really important tool for a scientist. Explore the Delphi components to learn what is available. Adding a main menu, about box, and other Windows features is not hard. Be creative!