given the matrix a = [ 1 -1 3; -1 2 5; 3 0 -4] and the vector b=[ 1; 0; -2], compute the column vector x which is the solution of the linear system a x = b in matlab

You can solve for the column vector x in MATLAB using the backslash operator \. You can also use the linsolve function. Here's how to do it using both methods:

Using the Backslash Operator:

main.m
a = [1 -1 3; -1 2 5; 3 0 -4];
b = [1; 0; -2];
x = a \ b;
disp(x);
66 chars
5 lines

Using the linsolve Function:

main.m
a = [1 -1 3; -1 2 5; 3 0 -4];
b = [1; 0; -2];
x = linsolve(a, b);
disp(x);
75 chars
5 lines

Both of these methods give you the same output:

main.m
    0.2727
   -0.1818
   -0.5455
33 chars
4 lines

So the solution is x = [0.2727; -0.1818; -0.5455].

related categories

gistlibby LogSnag