Matrix Syntax: Least Squares Solution - in Other Words, A Solution That Minimizes The Length of The Vector Ax - B
Matrix Syntax: Least Squares Solution - in Other Words, A Solution That Minimizes The Length of The Vector Ax - B
Syntax
mldivide(A,B) A\B
mrdivide(B,A) B/A
Description
mldivide(A,B) and the equivalent A\B perform matrix left division (back slash). A and B must
be matrices that have the same number of rows, unless A is a scalar, in which case A\B performs
element-wise division — that is, A\B = A.\B.
If A is a square matrix, A\B is roughly the same as inv(A)*B, except it is computed in a different
way. If A is an n-by-n matrix and B is a column vector with n elements, or a matrix with several
such columns, then X = A\B is the solution to the equation AX = B. A warning message is
displayed if A is badly scaled or nearly singular.
mrdivide(B,A) and the equivalent B/A perform matrix right division (forward slash). B and A
must have the same number of columns.
If A is a square matrix, B/A is roughly the same as B*inv(A). If A is an n-by-n matrix and B is a
row vector with n elements, or a matrix with several such rows, then X = B/A is the solution to
the equation XA = B computed by Gaussian elimination with partial pivoting. A warning
message is displayed if A is badly scaled or nearly singular.
Note Matrix right division and matrix left division are related by the equation
B/A = (A'\B')'.
If the equation Ax = b does not have a solution (and A is not a square matrix), x = A\b returns a
least squares solution — in other words, a solution that minimizes the length of the vector Ax - b,
which is equal to norm(A*x - b). See Example 3 for an example of this.
Examples
Example 1
A = magic(3)
A=
8 1 6
3 5 7
4 9 2
b = [1;2;3]
b=
1
2
3
x=A\b
x=
0.0500
0.3000
0.0500
A*x
ans =
1.0000
2.0000
3.0000
Example 2 — A Singular
A = magic(5);
A(:,1) = zeros(1,5); % Set column 1 of A to zeros
b = [1;2;5;7;7];
x = A\b
Warning: Matrix is singular to working precision.
ans =
NaN
NaN
NaN
NaN
NaN
If you get this warning, you can still attempt to solve Ax = b using the pseudoinverse function
pinv.
x = pinv(A)*b
x=
0
0.0209
0.2717
0.0808
-0.0321
The result x is least squares solution to Ax = b. To determine whether x is a exact solution — that
is, a solution for which Ax - b = 0 — simply compute
A*x-b
ans =
-0.0603
0.6246
-0.4320
0.0141
0.0415
Example 3
Suppose that
A = [1 0 0;1 0 0];
b = [1; 2];
Note that Ax = b cannot have a solution, because A*x has equal entries for any x. Entering
x = A\b
x=
1.5000
0
0
along with a warning that A is rank deficient. Note that x is not an exact solution:
A*x-b
ans =
0.5000
-0.5000
Class Support
When computing X = A\B or X = A/B, the matrices A and B can have data type double or single.
The following rules determine the data type of the result:
In algebra, the determinant is a particular number related with some square matrix. The
essential geometric significance of a determinant is a scale factor for compute when the matrix is
considered as a linear transformation. Thus a 3 xx 3 matrix with determinant 3 when useful to a
place of points with fixed area will convert those points into a place with double the area.
Determinants are significant together in calculus, where they go into the replacement rule for
various variables, and in multi linear algebra.
Solution:
Initially, write down the entrance the matrix B, other than write in a double-wide matrix:
In the added partially of the double-wide, write down the identity matrix:
At this moment we will perform matrix row operations to exchange the LHS of the
double-wide to the identity. (As constantly with row operations, here no one "correct" way to do
this pursue are just the steps that occur to me. Our estimate can be simply looking moderately
different.
At this moment that the LHS of the double-wide include the identity, the RHS include the
inverse. That is, the inverse matrix is the following:
Initially, write down the entrance the matrix B, other than write in a double-wide matrix:
In the added partially of the double-wide, write down the identity matrix:
At this moment we will perform matrix row operations to exchange the LHS of the
double-wide to the identity. (As constantly with row operations, here no one "correct" way to do
this pursue are just the steps that occur to me. Our estimate can be simply looking moderately
different.)
At this moment that the LHS of the double-wide include the identity, the RHS include the
inverse. That is, the inverse matrix is the following:
Ans:
Basic counting principle:
3! = 3•2•1 = 6 ways
4. There are fourteen juniors and twenty-three seniors in the Service Club. The club is to send
four representatives to the State Conference.
a.) How many different ways are there to select a group of four students to attend the
conference?
b.) If the members of the club decide to send two juniors and two seniors, how many different
groupings are possible?
Ans:
14 juniors, 23 seniors
37 students total
a.) Choose 4 students from the total number of students. Order is not important.
Geometric Progression:
Formula:
Example:
Find the 6th term of the Geometric sequence 64, 16, 4....
Solution: a = 64, r = 16 / 64
r = 1/4
t6 = ar6–1
= ar5
= 64(1/1024)
t6 = 1/16
Arithmetic Progression:
Formula:
Find the 11th term of an Arithmetic progression 12, 16, 20, 24…...
Solution:
= 12 + 10 (4)
= 12 + 40
Solution: t 11 = 45
2) Find the 8th term of the Geometric progressions sequence 343, 49, 7...
4) Find the 7th term of the Geometric sequence 64, 16, 4....