how to create a system of 3 equations in matlab

To create a system of 3 equations in MATLAB, you can define your system of equations using matrices and vectors.

For instance, consider the system:

main.m
x + y - z = 1
2x - y + z = 3
3x + y + z = 1
44 chars
4 lines

We can represent this system in the form Ax=b, where A is a 3x3 matrix, x is a 3x1 vector of unknowns, and b is a 3x1 vector of constants.

Here's how you can create this system in MATLAB:

main.m
% Define the matrix A
A = [1 1 -1; 
     2 -1 1; 
     3 1 1];

% Define the vector b
b = [1; 3; 1];

% Solve the system Ax = b for x
x = A\b;
143 chars
11 lines

The backslash operator \ performs matrix left division in MATLAB, which solves the system Ax=b for x.

After executing this code, the vector x will contain the solution to the system of equations, which in this case is x = [-1; 2; -2].

gistlibby LogSnag