In this chapter we have shown how to use elementary row operations to solve systems of linear equations. We have assumed that each linear equation in the system has the form where the s and the s are real numbers. For simplicity, in our examples we have only chosen equations with integer coefficients — such as:
Systems with Nonrational Coefficients
In fact, a more general choice of coefficients for a system of two equations might have been
Suppose that we solve (??) by elementary row operations. In matrix form we have the augmented matrix Proceed with the following elementary row operations. Divide the row by to obtain Next, subtract times the row from the row to obtain: Then divide the row by , obtaining: Finally, multiply the row by and subtract it from the row to obtain: So
Both and are real numbers — they had to be because all of the manipulations involved addition, subtraction, multiplication, and division of real numbers — which yield real numbers.
If we wanted to use MATLAB to perform these calculations, we have to convert , , and to their decimal equivalents — at least up to a certain decimal place accuracy. This introduces errors — which for the moment we assume are small.
To enter and in MATLAB , type
A = [sqrt(2) 2*pi; 3 36.2];Now type A to obtain:
b = [22.4; exp(1)];
A =As its default display, MATLAB displays real numbers to four decimal place accuracy. Similarly, type b to obtain
1.4142 6.2832
3.0000 36.2000
b =
22.4000
2.7183
Next use MATLAB to solve this system by typing:
A\bto obtain
ans =
24.5417
-1.9588
The reader may check that this answer agrees with the answer in (??) to MATLAB output accuracy by typing
x1 = 11.2*sqrt(2)-pi*sqrt(2)*(exp(1)-33.6*sqrt(2))/(36.2-3*pi*sqrt(2))to obtain
x2 = (exp(1)-33.6*sqrt(2))/(36.2-3*pi*sqrt(2))
x1 =and
24.5417
x2 =
-1.9588
More Accuracy
MATLAB can display numbers in machine precision (15 digits) rather than the standard four decimal place accuracy. To change to this display, type
format longNow solve the system of equations (??) again by typing
A\band obtaining
ans =
24.54169560069650
-1.95875151860858
Integers and Rational Numbers
Now suppose that all of the coefficients in a system of linear equations are integers. When we add, subtract or multiply integers — we get integers. In general, however, when we divide an integer by an integer we get a rational number rather than an integer. Indeed, since elementary row operations involve only the operations of addition, subtraction, multiplication and division, we see that if we perform elementary row operations on a matrix with integer entries, we will end up with a matrix with rational numbers as entries.
MATLAB can display calculations using rational numbers rather than decimal numbers. To display calculations using only rational numbers, type
format rationalFor example, let To verify these statements, calculate
and
Exercises
Solve the systems of linear equations given in Exercises ?? – ?? and verify that the answers are rational numbers.
In Exercises ?? – ?? use MATLAB to solve the given system of linear equations to four significant decimal places.