Least square fitting

Least square fitting
. Develop appropriate solutions to technological problems
. Describe and apply features of an objected-orientated programming language
. E ectively exploit the programming language and development environments
5.1 Least-squares fitting
In engineering applications we often have to fit a mathematical model to data, often experimental data that are
subject to measurement errors. This assignment is to do exactly that in one of the simplest cases – fitting a straight
line to a set of measurements that ought to lie on a straight line but that don’t quite do so because of measurement
This process is known as a least-squares fit, because of the algorithm used. The mathematics behind a linear
(straight line) least-squares fit are quite simple and are well known and widely documented. They are summarised
in a document: “An introduction to least-squares fitting”, available on Blackboard.
“An introduction. . . ” gives some simple examples and some references; in this assignment we shall concentrate
on determining the best equation
y = a + bx
that fits a data set such as that given in figure 1. In other words, for a given data set we have to determine
. Our best estimates of the parameters a (the “intercept”) and b (the “slope”).
. The estimated uncertainty in intercept and slope.
Least squares fitting is very powerful and very interesting, and is something about which every engineer should
know. Nonetheless, the purpose of this assignment is not to study the technique itself but to develop a useful
software application implementing algorithms provided (as pseudocode) in “An introduction. . . ”
5.2 Example data and GUI application
Figure 1 shows some example data suitable for a straight-line fit. These data are available on Blackboard (as file
data.txt) to support your testing your application. Your application will have to read data from a file such as this.
Note that the data come in x; y pairs, one to a line, separated by tab characters. Note also that the first line contains
Page 2 of 8
University of Central Lancashire
School of Computing, Engineering & Physical Sciences
EL2311 Coursework Assignment
xi yi
0 -3.347808
0.1 -2.594193
0.2 -1.930295
0.3 -0.647211
0.4 0.315137
0.5 1.543327
0.6 1.370375
0.7 3.110938
0.8 3.05416
0.9 4.061771
1 4.627437
1.1 5.933753
1.2 6.281999
1.3 6.421473
1.4 7.175764
1.5 7.668333
1.6 9.165742
1.7 10.055097
1.8 9.839108
1.9 10.441661
2 12.195463
2.1 12.758102
2.2 12.897014
2.3 12.906194
2.4 14.205887
2.5 15.644408
Figure 1: Example least-squares-fit data set
column headings, not data. This helps the human reader interpret the file; your software will also have to deal with
it and you have the challenge of achieving that.
Figure 2 is a screenshot of my model answer processing the data of figure 2.1 Your program should behave
similarly, although it is not necessary for it to mimic mine closely.
Observe that there is a graphical user interface with a facility for entering the file name as a text string. Your
program should also have a GUI, and must be capable of reading data from a file whose name is specified by the
user, not by the programmer.
There are textual and graphical displays, showing the data from the file. Your program should also display the
file contents as text and as a plot. The text display is – should be – easy; the plot will be trickier.
There are controls for quitting the application (of course), and for doing the fit. When the fit is done, the graph
is updated (slightly tricky) and parameter values and uncertainties are displayed (easier). Your program should
also behave similarly.
Of course, we have here a GUI class using Widgets from the SCAT graphics library. But there are also
additional classes and functions behind the scenes, to make it easier to read and fit the data. Your program should
also use object-orientated techniques to achieve similar results.
5.3 Assignment requirements
Your brief is to develop an application program to analyse data such as those in figure 1.
The application shall meet the following general requirements
1. Be written entirely in standard C++.
2. Be developed using Visual Studio 2010 and the SCAT toolset used in this module. (Any edition of Visual
Studio 2010 is acceptable; the deliverable will be in the form of a Visual Studio 2010 solution, and assess-
1 I see that I have used a di erent convention: m for slope and c for intercept. But it’s the same equation: y = mx + c.
Page 3 of 8
University of Central Lancashire
School of Computing, Engineering & Physical Sciences
EL2311 Coursework Assignment
Figure 2: Example least-squares-fit GUI
ment will include building and debugging using the Visual Studio 2010 Ultimate Edition on the UCLan
corporate Windows 7 network.)
A fully compliant application shall also meet the following specific requirements:
1. Have a graphical user interface, similar to that shown in figure 2.
2. Read the name of a text file containing data formatted (in x; y pairs) as in figure 1.
3. Read the data from the file.
4. Display the data as text.
5. Plot the data as points on a simple graph.
6. Determine and display the parameters of the best straight line fit to the data in the file, using the algorithm
provided in “An introduction. . . ”.
7. Determine and display the uncertainty in the least-squares fit parameters, using the algorithm provided in
“An introduction. . . ”.
8. Plot the best fit line on the same axes as the data points.
5.4 Additional guidance
I expect that all students will meet all the general requirements and at least some of the specific requirements.
Failure to meet all the specific requirements will not necessarily lead to mark below the pass mark for this assignment.
Page 4 of 8
University of Central Lancashire
School of Computing, Engineering & Physical Sciences
EL2311 Coursework Assignment
At the time of publishing this assignment we have already studied all the software development techniques
required to construct my model answer, except for the plot. The plotting is the most challenging part, partly
because the plotting capability of the libscat library is limited. Attempt it last.
Probably, the most useful order in which you should approach this development activity is as follows:
1. GUI design
2. File IO
3. Data display (text)
4. Fit calculation
5. Fit display (text)
6. Data display (plot)
7. Fit display (plot)
The checklist shown in Appendix C identifies the things I shall be looking for in your submissions and is
intended to help you check your progress and your achievement against the requirements. Please also submit a
copy (in pdf, in your zip file); it will form a useful self-evaluation and will help me find the evidence required to
evaluate your work.
My model answer has about 400 lines of source code (including white space and comments) in 7 files (*.cpp
and *.h).
A discussion forum for the assignment is available on Blackboard. Please ask questions there.
Page 5 of 8
University of Central Lancashire
School of Computing, Engineering & Physical Sciences
EL2311 Coursework Assignment
A Grade scale
Develop appropriate
solutions to technological
Describe and apply
features of an objectorientated
E ectively exploit the
programming language
and development environments
E ectively apply software
design and development
Correct and ecient
operation meeting all
specified requirements
with robust error handling
throughout, even in
pathological cases.
Sophisticated application
of object-orientated programming
features as appropriate
to the specific
Near-optimum selection
of features from the programming
language and
supporting libraries.
Application of suitable
standard algorithms, going
beyond material explicitly
covered in class.
Full and reliable implementation
of specified
requirements, including
an e ective graphical
user interface.
Proper management of
invariants and of system
resources, especially
memory. E ective use of
abstract and concrete
classes, and of polymorphism.
Comprehensive use of
language and library features
including some use
of features beyond the
examples demonstrated
in class. Accomplished
use of automatic code
E ective error handling,
including the use of assertions
and exceptions.
Selection and application
of suitable additional test
Reliable operation with
no significant errors in
most or all use cases.
E ective design of a user
interface and of event
E ective design of
classes, including at
least one derived class,
accounting for the principles
of encapsulation
and inheritance.
Comprehensive use of
stream IO. E ective use
of features from at least
one non-standard library.
Use of automatic code
E ective use of defensive
programming principles
to ensure reliability.
Suitable choice and
e ective use of parameter
passing paradigms.
E ective use of source
code comments.
Successful compilation
without warnings.
Correct execution of at
least a baseline feature
Correct selection and use
of library classes and
Correct use of standard
containers or other aggregate
data structures.
Suitable partitioning
of source code. Wellchosen
function designs.
Adequate use of source
code comments.
Successful compilation
and execution in at least
some use cases.
Valid creation and use of
at least one class type.
Successful stream and
file IO, and successful
selection and use of built
in data types and operators
and standard library
Proper use of postcondition
checks where
needed. Appropriate
source code layout and
naming. Correct function
Unsuccessful compilation
or inability to execute
without significant errors
occurring in most or all
use cases.
No use or incorrect use
of user-defined data
Significant errors in the
use of features from the
language, libraries or development
Little or no evidence of
application of software
design principles.
Failure to comprehend
or address the learning
Failure to comprehend
or address the learning
Failure to comprehend
or address the learning
Failure to comprehend
or address the learning
80 80
70 70
60 60
50 50
40 40
30 30
Page 6 of 8
University of Central Lancashire
School of Computing, Engineering & Physical Sciences
EL2311 Coursework Assignment
B Extracts from Academic Regulations
Also see http://www.uclan.ac.uk/aqasu/academic_regulations.php.
B.1 Late submission
Academic regulations section G3 refers:
The University operates a universal penalty scale for unauthorised late submission of any form of
assessed work. Students who submit work within 5 working days after the published submission date
without an authorised extension will obtain a maximum of [40%] for that element of assessment. All
work submitted later than 5 days after the published submission date will be awarded a mark of 0%
for that element of assessment.
. “5 days” means five days excluding weekdays, i.e. seven calendar days.
B.2 Unfair means to enhance performance
Academic regulations section G7 refers:
Unfair means includes all forms of cheating, plagiarism, collusion and re-presentation . . .
All instances or allegations of the use of unfair means will be investigated . . .
In the event of a single o ence of cheating, plagiarism, collusion and re-presentation in an undergraduate
or postgraduate assessment, the appropriate penalty will be 0% for that element of assessment, and
an overall fail for the module . . . The plagiarised element of assessment must be resubmitted to the
required standard. The mark for the module following resubmission will be restricted to [40%] . . .
In the event of a repeat o ence . . . on the same or any other module within the course, the appropriate
penalty will be 0% for the module with no opportunity for re-assessment.
. When one student copies from another, with the other’s permission or even as a result of inadvertence on
the part of the second student, both students are liable to be penalised for collusion.
. “Re-presentation” (the hyphen is significant) means submitting the same work, or substantially the same
work, for more than one assessment.
Page 7 of 8
University of Central Lancashire
School of Computing, Engineering & Physical Sciences
EL2311 Coursework Assignment
C Submission checklist
EL2311 2013/14 assignment checklist Student:
Complete this checklist and submit it with your assignment to:
• Help you ensure that you have demonstrated the skills that the assignment is intended to assess
• Help you identify the evidence needed to give you the credit you deserve
• This is not a checklist for passing. You do not have to demonstrate all of these things to achieve a pass mark for this
assignment. But model answers, achieving full marks, ought to demonstrate most or all of the skills identified here
• If you don’t know the meaning of any of the terms given in the left-hand column, you should refer to the module
materials on Blackboard and to the recommended texts, especially Stroustrup’s “Programming Principles and Practice.”
What have you demonstrated? Where is the evidence? (File names, line numbers, etc.)
C++ standard library features
. Containers
. File stream IO
. String stream IO
. Mathematics
SCAT library features
. Graphics
. Widgets
Procedural programming
. Function design
. Pass by reference
. Pass by constant reference
Object-orientated programming
. Data type design
. Encapsulation
. Inheritance
. Resource management
Event-driven programming
. GUI design
. Callback implementation
Error handling
. Precondition checks
. Postcondition checks
. Invariants
. Throwing exceptions
. Catching exceptions
Code partitioning
. File naming
. File location
. File contents
. File inclusion
. Include guards
Code documentation
. Good program layout
. Effective naming
. Effective comments
. Doxygen-style comments

Calculate your order
275 words
Total price: $0.00

Top-quality papers guaranteed


100% original papers

We sell only unique pieces of writing completed according to your demands.


Confidential service

We use security encryption to keep your personal data protected.


Money-back guarantee

We can give your money back if something goes wrong with your order.

Enjoy the free features we offer to everyone

  1. Title page

    Get a free title page formatted according to the specifics of your particular style.

  2. Custom formatting

    Request us to use APA, MLA, Harvard, Chicago, or any other style for your essay.

  3. Bibliography page

    Don’t pay extra for a list of references that perfectly fits your academic needs.

  4. 24/7 support assistance

    Ask us a question anytime you need to—we don’t charge extra for supporting you!

Calculate how much your essay costs

Type of paper
Academic level
550 words

How to place an order

  • Choose the number of pages, your academic level, and deadline
  • Push the orange button
  • Give instructions for your paper
  • Pay with PayPal or a credit card
  • Track the progress of your order
  • Approve and enjoy your custom paper

Ask experts to write you a cheap essay of excellent quality

Place an order

Order your essay today and save 7% with the discount code DISSERT7