MATLAB: Solving unknown variables in matrices

equationMATLABmatrix

So for un I've got to solve 3 variables from the equation y = k*x^2 + l*x + m, given are points P(-2, 4) Q(1,1) and R(2, -4). We are also instructed to use matrices.
I though a logical next step would be to make a matrix, matrix=[-2, 4;1, 1;2, -4]
From this you can make 3 linear equations, one for every row of the matrix. Is there a way to build and solve such an 'equation matrix' using Matlab? Or do I just have to do this by hand by treating it as a system of 3 coupled equations, which in this case isn't that difficult.
I've tried introducting the variables k, l and m into a matrix and making equations in there, but this hasnt worked.

Best Answer

You need to solve an linear optimization problem A*x = b. Each line is one of your points P,Q,R.
  • b is the solution vector and contains the y-variable of your three given points P,Q,R
b = [4 ; 1 ; -4]
  • x is the vector of (unknown) parameters, this means that
  • Each column of a corresponds to either x^0, x^1 or x^2 (for all points P,Q,R):
A = [1 -2 4;
1 1 1;
1 2 4]
The solution (where x = [m;l;k] ) is:
x = A\b
Related Question