Prove that the least squares general straight-line model gives the absolute minimum of the sum of the squares of the residuals?

Many regression models when derived in books only show the first derivative test to find the formulas for the constants of a linear regression model.  Here we show a thoroughly explained derivation.



___________________________________________

This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com, the textbook on Numerical Methods with Applications available from the lulu storefront, the textbook on Introduction to Programming Concepts Using MATLAB, and the YouTube video lectures available at http://nm.mathforcollege.com/videos.  Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.

Effect of Significant Digits: Example 2: Regression Formatting in Excel

In a series of bringing pragmatic examples of the effect of significant digits, we discuss the influence of using default and scientific formats in the trendline function of Microsoft Excel.  This is the second example (first example was on a beam deflection problem) in the series.

____________________________________________

This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com, the textbook on Numerical Methods with Applications available from the lulu storefront, the textbook on Introduction to Programming Concepts Using MATLAB, and the YouTube video lectures available at http://nm.mathforcollege.com/videos.  Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.

Effect of Significant Digits: Example 1: Beam Deflection

In a series of bringing pragmatic examples of the effect of significant digits, we discuss the exact solution of finding the deflection in a simply supported beam with a uniform load and a tensile axial load.

___________________________________________

This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com, the textbook on Numerical Methods with Applications available from the lulu storefront, the textbook on Introduction to Programming Concepts Using MATLAB, and the YouTube video lectures available at http://nm.mathforcollege.com/videos.  Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.

Length of curve

This is a solution to the problem I gave to the class in a recent test.

A robot follows a path generated by a quadratic interpolant from x=2 to x=4.  The interpolant passes through three consecutive data points (2,4), (3,9) and (4,16) and is given by y=x2.  Find the best estimate of the length of the interpolant path from x=2 to x=4. 

The solution is given as an audio pdf (also called pencast – need Adobe X reader or higher). Three methods are shown. I expected one to use Method 2 or Method 3.
http://www.eng.usf.edu/~kaw/class/EML3041/livescribe/length_of_curve.pdf

______________________________________________________________

This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com, the textbook on Numerical Methods with Applications available from the lulu storefront, the textbook on Introduction to Programming Concepts Using MATLAB, and the YouTube video lectures available at http://nm.mathforcollege.com/videos.  Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.

Example: How many significant digits are correct in my answer?

In the previous post I showed you the theorem that tells us how many significant digits are correct in our numerical solution that is iterative in nature.  In this post, we illustrate this with an example.

__________________________________________
This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com, the textbook on Numerical Methods with Applications available from the lulu storefront, the textbook on Introduction to Programming Concepts Using MATLAB, and the YouTube video lectures available at http://nm.mathforcollege.com/videos.  Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.

 

How many significant digits are correct in my answer?

To find how many significant digits are correct in my answer in a numerical method that gives iterative values, one finds the absolute relative approximate  percentage error defined as
|(Current approximation-Previous approximation)/Current approximation|*100
If the absolute relative approximate percentage error is less than or equal to 0.5*10^(2-m), then m significant digits are at least correct in the answer.
For example, if you want

  • at least 1 signficant digit to be correct in your answer, your absolute relative approximate error should be less than or equal to 5%
  • at least 2 signficant digit to be correct in your answer, your absolute relative approximate error should be less than or equal to 0.5%
  • at least 3 signficant digit to be correct in your answer, your absolute relative approximate error should be less than or equal to 0.05%
    and so on.

In the next blog, we will illustrate this concept via an example.
___________________________________________
This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com, the textbook on Numerical Methods with Applications available from the lulu storefront, the textbook on Introduction to Programming Concepts Using MATLAB, and the YouTube video lectures available at http://nm.mathforcollege.com/videos.  Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.

Do we have to setup all 3n equations for the n quadratic splines for (n+1) data points?

QUESTION ASKED BY STUDENT: For linear splines, we still find each line individually. In quadratic, we are forced to find every equation at once, correct? Which is where the matrix comes from?

ANSWER: That sounds right, but one can find quadratic equations individually also .
How?
If the first spline is linear, then that spline can be found by the two points it goes through.
Then the second spline goes thru two points, and that gives two equations.  The slope of the second spline is same as the slope of first spline at the common interior point, and the first spline is known. This gives the third eqn.  This process can be repeated for each following spline.

____________________________________

This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com, the textbook on Numerical Methods with Applications available from the lulu storefront, the textbook on Introduction to Programming Concepts Using MATLAB, and the YouTube video lectures available at http://nm.mathforcollege.com/videos.  Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.

Largest integer that can be represented in a n-bit integer word

To find the largest integer in base-10 that can be represented in an n-bit integer word, let’s do this inductively.

  • If you have 3 bit-word, the highest number is (111) of base-2 which is 7 (1*2^2+1*2^1+1*2^0) of base-10,
  • If you have 4 bit-word, the highest number is (1111) of base-2 which is 15 (1*2^3+1*2^2+1*2^1+1*2^0) of base-10,
  • if you have 5 bit-word, the highest number is (11111) of base-2 which is 31 (1*2^4+1*2^3+1*2^2+1*2^1+1*2^0) of base-10. 

There is a trend here: 3 bit-word stores a maximum number of 7 (2^3-1), 4-bit word stores a maximum of 15 (2^4-1), 5 bit-word store a maximum number of 31 (2^5-1), and so on.   This means that the maximum number stored in n-bit word stores a maximum number of 2^n-1. 

We can derive the maximum number by knowing that the maximum base-10 number in a n-bit word is the summation series:
1*2^(n-1)+1*2^(n-2)+………+1×2^0. 
This is a geometric progression series.  The formula for the sum of a geometric series
        a+ar+ar^2+…+a*r^n =a*(1-r^(n+1))/(1-r), r ≠ 1,
Hence,
       1*2^(n-1)+1*2^(n-2)+………+1×2^0=1*(1-2^(n))/(1-2)=2^n-1 _____________________________________________________________

This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com, the textbook on Numerical Methods with Applications available from the lulu storefront, the textbook on Introduction to Programming Concepts Using MATLAB, and the YouTube video lectures available at http://nm.mathforcollege.com/videos.  Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.

Differentiating a Discrete Function with Equidistant Points

Many students ask me how do I do this or that in MATLAB.  This is a new addition to the “How do I do that in MATLAB”  series.
 
In this blog, I show you how to find the first derivative of a discrete function y(x).  We are assuming that the x values are eqidistant and the data is sorted in ascending or descending order by the x values.  The latter requirement can be relaxed easily in programs such as MATLAB where one can use the sortrows command to put the data in the required order.
 
To keep the accuracy of all calculated first derivatives to be the same, we use the following formulas:
 
For the first data point, we use the forward divided difference formula
        f ‘(x) =(-f(x+2h) + 4 f(x+h) -3 f(x))/(2h)+order(h^2)
 
For the interior points, we use the central divided difference formula
       f ‘(x) =(f(x+h) -f(x-h))/(2h)+order(h^2)
 
For the last data point, we use the backward divided difference formula
       f ‘(x) =(f(x-2h) – 4 f(x-h) +3 f(x))/(2h)+order(h^2)
 
Here are the links for the program.
The mfile is here
The published version of the mfile is here

%% HOW DO I DO THAT IN MATLAB SERIES?
% In this series, I am answering questions that students have asked
% me about MATLAB.  Most of the questions relate to a mathematical
% procedure.

%% TOPIC
% How do I find the first derivative of a discrete function y(x) if the
% x values are equidistant.
%% SUMMARY
% Language : Matlab 2010a;
% Authors : Autar Kaw and Sri Garapati;
% Mfile available at
% http://nm.mathforcollege.com/blog/discrete_diff_equidistant_blog.m
% Last Revised : January 17, 2012;
% Abstract: This program shows you how to differentiate discrete data if
% the x values are equally spaced
clc
clear all

%% INTRODUCTION

disp(‘ABSTRACT’)
disp(‘   This program shows you how to differentiate discrete data if’)
disp(‘   the x values are equally spaced ‘)

disp(‘ ‘)
disp(‘AUTHOR’)
disp(‘   Autar Kaw and Sri Garapati of http://autarkaw.wordpress.com’)
disp(‘ ‘)
disp(‘MFILE SOURCE’)
disp(‘   http://nm.mathforcollege.com/blog/discrete_diff_equidistant_blog.m’)
disp(‘ ‘)
disp(‘LAST REVISED’)
disp(‘   January 17, 2012’)
disp(‘ ‘)

%% INPUTS

% Inputs assuming
%    that three or more points are given
%    all x values are equidistant
%    x values are in ascending or descending order.
x=[2.3   3.4   4.5    5.6   6.7   7.8];
y=[4.6   7.9   13.0   12.3  3.2   1.9];
%% DISPLAYING INPUTS
disp(‘  ‘)
disp(‘INPUTS’)
% Creating a matrix to print input data as a table
data=[x;y]’;
disp(‘   X Data     Y Data’)
% Printing the input data as a table
disp(data)

%% THE CODE

% n returns the number of data points
n=length(x);
% delta is the distance between consecutive x values
delta=x(2)-x(1);

% “dy” is an array which stores the value of the derivative at each x-value

% finding the derivative from the 2nd order accurate forward divided
% difference formula at the first data point
dy(1)=(-y(3)+4*y(2)-3*y(1))/(2*delta);

% finding the derivative from the 2nd order accurate central divided
% difference formula at the second to (n-1)th data point
for i=2:1:n-1
    dy(i)=(y(i+1)-y(i-1))/(2*delta);
end

% finding the derivative from the 2nd order accurate backward divided
% difference formula at the first data point
dy(n)=(y(n-2)-4*y(n-1)+3*y(n))/(2*delta);

% creating a matrix with input data and calculated derivative value at
% each data point for printing as a table
xdy=[x’ y’ dy’];

%% DISPLAYING OUTPUTS
disp(‘  ‘)
disp(‘OUTPUTS’)
disp(‘     XData   YData  Derivative’)
% printing the input data points and calculated derivative values(Outputs)
disp(xdy)
_________________________________________________

This post is brought to you by Holistic Numerical Methods: Numerical Methods for the STEM undergraduate at http://nm.mathforcollege.com, the textbook on Numerical Methods with Applications available from the lulu storefront, the textbook on Introduction to Programming Concepts Using MATLAB, and the YouTube video lectures available at http://nm.mathforcollege.com/videos.  Subscribe to the blog via a reader or email to stay updated with this blog. Let the information follow you.