
8 - Chapman MATLAB Programming for Engineers
.pdfSystems of linear equations can also be solved symbolically. Consider the following example that was previously solved numerically:
>>syms x
>>A = sym([3 2 -1; -1 3 2; 1 -1 -1])
A =
[ |
3, |
2, |
-1] |
[ |
-1, |
3, |
2] |
[1, -1, -1]
>>b = sym([10; 5; -1])
b = [ 10] [ 5] [ -1]
>>x = A\b
x = [ -2] [ 5] [ -6]
The results are the same as those obtained numerically. For this problem, there is little advantage to finding the result symbolically. However, solving a system of equations with respect to a parameter, the symbolic approach provides an advantage. Consider the following set of equations
2x1 − 3x2 = 3
5x1 + cx2 = 19
To solve for x1 and x2 as functions of the parameter c:
>>syms c
>>A = sym([2 -3; 5 c]);
>>b = sym([3; 19]);
>>x = A\b
x =
[ 3*(19+c)/(2*c+15)]
[23/(2*c+15)]
267