Page 261 - MATLAB an introduction with applications
P. 261

246 ———  MATLAB: An Introduction with Applications

                   The final solution is
                         1
                         2
                         3
                   MATLAB solution is
                   x =
                         1
                         2
                         3
                   Check with MATLAB built-in function:

                   >> A = [6 3 6;2 3 3;1 2 2];
                   b = [30;17;11];
                   >>
                   >> x=A\b

                   x =
                       1
                       2
                       3

                   Example E4.22: Using Choleski’s method, solve the following linear equations:
                              x + x + x = 7
                               1
                                       3
                                   2
                            3x + 3x + 4x = 23
                             1
                                  2
                                       3
                              2x + x + x = 10
                                   2
                                       3
                               1
                   Solution: The complete program and output are given below:
                   A = [1 1 1;3 3 4;2 1 1];
                   b = [7;23;10];
                   [L,U] = lu(A);
                   % solution of y
                   y = L\b;
                   %final solution x
                   x = U\y;
                   fprintf(‘Solution of the equations is\n’);
                   disp(x)
                   Solution of the equations is
                         3.0000
                         2.0000
                         2.0000
   256   257   258   259   260   261   262   263   264   265   266