# Least square fitting

Least square fitting
. Develop appropriate solutions to technological problems
. Describe and apply features of an objected-orientated programming language
. Eectively 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
errors.
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 dierent 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
problems
Describe and apply
features of an objectorientated
programming
language
Eectively exploit the
programming language
and development environments
Eectively apply software
design and development
principles
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
requirements.
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 eective graphical
user interface.
Proper management of
invariants and of system
resources, especially
memory. Eective 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
documentation.
Eective error handling,
including the use of assertions
and exceptions.
Selection and application
of suitable additional test
sets.
Reliable operation with
no significant errors in
most or all use cases.
Eective design of a user
interface and of event
handlers.
Eective design of
classes, including at
least one derived class,
accounting for the principles
of encapsulation
and inheritance.
Comprehensive use of
stream IO. Eective use
of features from at least
one non-standard library.
Use of automatic code
documentation.
Eective use of defensive
programming principles
to ensure reliability.
Suitable choice and
eective use of parameter
passing paradigms.
Eective use of source
code comments.
Successful compilation
without warnings.
Correct execution of at
least a baseline feature
set.
Correct selection and use
of library classes and
objects.
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
functions
Proper use of postcondition
checks where
needed. Appropriate
source code layout and
naming. Correct function
implementation.
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
types.
Significant errors in the
use of features from the
language, libraries or development
environment.
Little or no evidence of
application of software
design principles.
Failure to comprehend
or address the learning
outcome.
Failure to comprehend
or address the learning
outcome.
Failure to comprehend
or address the learning
outcome.
Failure to comprehend
or address the learning
outcome.
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.
N.B.
. “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 oence 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 oence . . . 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.
N.B.
. 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
Note:
• 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
PLACE THIS ORDER OR A SIMILAR ORDER WITH US TODAY AND GET AN AMAZING DISCOUNT ?

# Our Service Charter

1. ### Excellent Quality / 100% Plagiarism-Free

We employ a number of measures to ensure top quality essays. The papers go through a system of quality control prior to delivery. We run plagiarism checks on each paper to ensure that they will be 100% plagiarism-free. So, only clean copies hit customers’ emails. We also never resell the papers completed by our writers. So, once it is checked using a plagiarism checker, the paper will be unique. Speaking of the academic writing standards, we will stick to the assignment brief given by the customer and assign the perfect writer. By saying “the perfect writer” we mean the one having an academic degree in the customer’s study field and positive feedback from other customers.
2. ### Free Revisions

We keep the quality bar of all papers high. But in case you need some extra brilliance to the paper, here’s what to do. First of all, you can choose a top writer. It means that we will assign an expert with a degree in your subject. And secondly, you can rely on our editing services. Our editors will revise your papers, checking whether or not they comply with high standards of academic writing. In addition, editing entails adjusting content if it’s off the topic, adding more sources, refining the language style, and making sure the referencing style is followed.
3. ### Confidentiality / 100% No Disclosure

We make sure that clients’ personal data remains confidential and is not exploited for any purposes beyond those related to our services. We only ask you to provide us with the information that is required to produce the paper according to your writing needs. Please note that the payment info is protected as well. Feel free to refer to the support team for more information about our payment methods. The fact that you used our service is kept secret due to the advanced security standards. So, you can be sure that no one will find out that you got a paper from our writing service.
4. ### Money Back Guarantee

If the writer doesn’t address all the questions on your assignment brief or the delivered paper appears to be off the topic, you can ask for a refund. Or, if it is applicable, you can opt in for free revision within 14-30 days, depending on your paper’s length. The revision or refund request should be sent within 14 days after delivery. The customer gets 100% money-back in case they haven't downloaded the paper. All approved refunds will be returned to the customer’s credit card or Bonus Balance in a form of store credit. Take a note that we will send an extra compensation if the customers goes with a store credit.
5. ### 24/7 Customer Support

We have a support team working 24/7 ready to give your issue concerning the order their immediate attention. If you have any questions about the ordering process, communication with the writer, payment options, feel free to join live chat. Be sure to get a fast response. They can also give you the exact price quote, taking into account the timing, desired academic level of the paper, and the number of pages.

Excellent Quality
Zero Plagiarism
Expert Writers

or

## Instant Quote

 Subject: Please Select... Art   Architecture   Dance   Design Analysis   Drama   Movies   Music   Paintings   Theatre Biology Business Chemistry Communications and Media   Advertising   Communication Strategies   Journalism   Public Relations Creative writing Economics   Accounting   Case Study   Company Analysis   E-Commerce   Finance   Investment   Logistics   Trade Education   Application Essay   Education Theories   Pedagogy   Teacher's Career Engineering English Ethics History   African-American Studies   American History   Asian Studies   Canadian Studies   East European Studies   Holocaust   Latin-American Studies   Native-American Studies   West European Studies Law   Criminology   Legal Issues Linguistics Literature   American Literature   Antique Literature   Asian Literature   English Literature   Shakespeare Studies Management Marketing Mathematics Medicine and Health   Alternative Medicine   Healthcare   Nursing   Nutrition   Pharmacology   Sport Nature   Agricultural Studies   Anthropology   Astronomy   Environmental Issues   Geography   Geology Philosophy Physics Political Science Psychology Religion and Theology Sociology Technology   Aeronautics   Aviation   Computer Science   Internet   IT Management   Web Design Tourism Type: Please Select... Essay Term Paper Research Paper Coursework Book Report Book Review Movie Review Dissertation Thesis Thesis Proposal Research Proposal Dissertation Chapter - Abstract Dissertation Chapter - Introduction Chapter Dissertation Chapter - Literature Review Dissertation Chapter - Methodology Dissertation Chapter - Results Dissertation Chapter - Discussion Dissertation Services - Editing Dissertation Services - Proofreading Formatting Admission Services - Admission Essay Admission Services - Scholarship Essay Admission Services - Personal Statement Admission Services - Editing Editing Proofreading Case Study Lab Report Speech Presentation Math Problem Article Article Critique Annotated Bibliography Reaction Paper PowerPoint Presentation Statistics Project Multiple Choice Questions (None-Time-Framed) Other (Not listed) Pages/Words: 1 page/approx 275 words 2 pages/approx 550 words 3 pages/approx 825 words 4 pages/approx 1100 words 5 pages/approx 1375 words 6 pages/approx 1650 words 7 pages/approx 1925 words 8 pages/approx 2200 words 9 pages/approx 2475 words 10 pages/approx 2750 words 11 pages/approx 3025 words 12 pages/approx 3300 words 13 pages/approx 3575 words 14 pages/approx 3850 words 15 pages/approx 4125 words 16 pages/approx 4400 words 17 pages/approx 4675 words 18 pages/approx 4950 words 19 pages/approx 5225 words 20 pages/approx 5500 words 21 pages/approx 5775 words 22 pages/approx 6050 words 23 pages/approx 6325 words 24 pages/approx 6600 words 25 pages/approx 6875 words 26 pages/approx 7150 words 27 pages/approx 7425 words 28 pages/approx 7700 words 29 pages/approx 7975 words 30 pages/approx 8250 words 31 pages/approx 8525 words 32 pages/approx 8800 words 33 pages/approx 9075 words 34 pages/approx 9350 words 35 pages/approx 9625 words 36 pages/approx 9900 words 37 pages/approx 10175 words 38 pages/approx 10450 words 39 pages/approx 10725 words 40 pages/approx 11000 words 41 pages/approx 11275 words 42 pages/approx 11550 words 43 pages/approx 11825 words 44 pages/approx 12100 words 45 pages/approx 12375 words 46 pages/approx 12650 words 47 pages/approx 12925 words 48 pages/approx 13200 words 49 pages/approx 13475 words 50 pages/approx 13750 words 51 pages/approx 14025 words 52 pages/approx 14300 words 53 pages/approx 14575 words 54 pages/approx 14850 words 55 pages/approx 15125 words 56 pages/approx 15400 words 57 pages/approx 15675 words 58 pages/approx 15950 words 59 pages/approx 16225 words 60 pages/approx 16500 words 61 pages/approx 16775 words 62 pages/approx 17050 words 63 pages/approx 17325 words 64 pages/approx 17600 words 65 pages/approx 17875 words 66 pages/approx 18150 words 67 pages/approx 18425 words 68 pages/approx 18700 words 69 pages/approx 18975 words 70 pages/approx 19250 words 71 pages/approx 19525 words 72 pages/approx 19800 words 73 pages/approx 20075 words 74 pages/approx 20350 words 75 pages/approx 20625 words 76 pages/approx 20900 words 77 pages/approx 21175 words 78 pages/approx 21450 words 79 pages/approx 21725 words 80 pages/approx 22000 words 81 pages/approx 22275 words 82 pages/approx 22550 words 83 pages/approx 22825 words 84 pages/approx 23100 words 85 pages/approx 23375 words 86 pages/approx 23650 words 87 pages/approx 23925 words 88 pages/approx 24200 words 89 pages/approx 24475 words 90 pages/approx 24750 words 91 pages/approx 25025 words 92 pages/approx 25300 words 93 pages/approx 25575 words 94 pages/approx 25850 words 95 pages/approx 26125 words 96 pages/approx 26400 words 97 pages/approx 26675 words 98 pages/approx 26950 words 99 pages/approx 27225 words 100 pages/approx 27500 words 101 pages/approx 27775 words 102 pages/approx 28050 words 103 pages/approx 28325 words 104 pages/approx 28600 words 105 pages/approx 28875 words 106 pages/approx 29150 words 107 pages/approx 29425 words 108 pages/approx 29700 words 109 pages/approx 29975 words 110 pages/approx 30250 words 111 pages/approx 30525 words 112 pages/approx 30800 words 113 pages/approx 31075 words 114 pages/approx 31350 words 115 pages/approx 31625 words 116 pages/approx 31900 words 117 pages/approx 32175 words 118 pages/approx 32450 words 119 pages/approx 32725 words 120 pages/approx 33000 words 121 pages/approx 33275 words 122 pages/approx 33550 words 123 pages/approx 33825 words 124 pages/approx 34100 words 125 pages/approx 34375 words 126 pages/approx 34650 words 127 pages/approx 34925 words 128 pages/approx 35200 words 129 pages/approx 35475 words 130 pages/approx 35750 words 131 pages/approx 36025 words 132 pages/approx 36300 words 133 pages/approx 36575 words 134 pages/approx 36850 words 135 pages/approx 37125 words 136 pages/approx 37400 words 137 pages/approx 37675 words 138 pages/approx 37950 words 139 pages/approx 38225 words 140 pages/approx 38500 words 141 pages/approx 38775 words 142 pages/approx 39050 words 143 pages/approx 39325 words 144 pages/approx 39600 words 145 pages/approx 39875 words 146 pages/approx 40150 words 147 pages/approx 40425 words 148 pages/approx 40700 words 149 pages/approx 40975 words 150 pages/approx 41250 words 151 pages/approx 41525 words 152 pages/approx 41800 words 153 pages/approx 42075 words 154 pages/approx 42350 words 155 pages/approx 42625 words 156 pages/approx 42900 words 157 pages/approx 43175 words 158 pages/approx 43450 words 159 pages/approx 43725 words 160 pages/approx 44000 words 161 pages/approx 44275 words 162 pages/approx 44550 words 163 pages/approx 44825 words 164 pages/approx 45100 words 165 pages/approx 45375 words 166 pages/approx 45650 words 167 pages/approx 45925 words 168 pages/approx 46200 words 169 pages/approx 46475 words 170 pages/approx 46750 words 171 pages/approx 47025 words 172 pages/approx 47300 words 173 pages/approx 47575 words 174 pages/approx 47850 words 175 pages/approx 48125 words 176 pages/approx 48400 words 177 pages/approx 48675 words 178 pages/approx 48950 words 179 pages/approx 49225 words 180 pages/approx 49500 words 181 pages/approx 49775 words 182 pages/approx 50050 words 183 pages/approx 50325 words 184 pages/approx 50600 words 185 pages/approx 50875 words 186 pages/approx 51150 words 187 pages/approx 51425 words 188 pages/approx 51700 words 189 pages/approx 51975 words 190 pages/approx 52250 words 191 pages/approx 52525 words 192 pages/approx 52800 words 193 pages/approx 53075 words 194 pages/approx 53350 words 195 pages/approx 53625 words 196 pages/approx 53900 words 197 pages/approx 54175 words 198 pages/approx 54450 words 199 pages/approx 54725 words 200 pages/approx 55000 words Single spaced approx 275 words per page Urgency (Less urgent, less costly): Please Select... 6 hours 12 hours 24 hours 48 hours 3 days 4 days 5 days 7 days 10 days 20 days 30 days Level: Choose High School Undergraduate Master Ph. D. Currency: USD GBP CAD AUD EUR Total Cost: NaN

Get 10% Off on your 1st order!